zoukankan      html  css  js  c++  java
  • 笔记0427

    1,

    String.IsNullOrEmpty 方法

    指示指定的字符串是 null 还是 Empty 字符串。

    语法:

    public static bool IsNullOrEmpty(
    	string value
    )

    参数

    value
    类型:System.String
    要测试的字符串。

    返回值

    类型:System.Boolean
    如果 value 参数为 null 或空字符串 (""),则为 true;否则为 false


    IsNullOrEmpty 是一种简便方法,它使您能够同时测试 String 是否为 null 或其值是否为 Empty
    result = s == null || s == String.Empty;

    示例:

    下面的示例确定三个字符串中的每个字符串是有一个值、为空字符串还是为 null
    using System;
    
    class Sample 
    {
        public static void Main() 
        {
        string s1 = "abcd";
        string s2 = "";
        string s3 = null;
    
        Console.WriteLine("String s1 {0}.", Test(s1));
        Console.WriteLine("String s2 {0}.", Test(s2));
        Console.WriteLine("String s3 {0}.", Test(s3));
        }
    
        public static String Test(string s)
        {
        if (String.IsNullOrEmpty(s)) 
            return "is null or empty";
        else
            return String.Format("(\"{0}\") is not null or empty", s);
        }
    }
    // The example displays the following output:
    //       String s1 ("abcd") is not null or empty.
    //       String s2 is null or empty.
    //       String s3 is null or empty.

    2,

    PlaceHolder 类

    动态存储网页上添加的服务器控件。

    public class PlaceHolder : Control
    备注:将 PlaceHolder 控件用作存储动态添加到网页的服务器控件的容器。PlaceHolder 控件不产生任何可见输出并且只能用作网页上其他控件的容器。可以使用 Control.Controls 集合添加、插入或移除 PlaceHolder 控件中的控件。

    3,

    LiteralControl 类

    表示 HTML 元素、文本和 ASP.NET 页中不需要在服务器上处理的任何其他字符串。

      System.Web.UI.LiteralControl

    public class LiteralControl : Control, 
    	ITextControl

    LiteralControl begin = new LiteralControl();
            begin.Text = "<table>";
            phroute.Controls.Add(begin);
    LiteralControl contentbegin = new LiteralControl();
                contentbegin.Text = "<tr><td>";
                phroute.Controls.Add(contentbegin);
    
    phroute.Controls.Add(linkbtn);
                LiteralControl contentend = new LiteralControl();
                contentend.Text = "</td></tr>";
                phroute.Controls.Add(contentend);
    
      LiteralControl end = new LiteralControl();
            end.Text = "</table>";
            phroute.Controls.Add(end);
            lblroute.Visible = true;

    4,String.IndexOf 方法

    String.IndexOf(String):报告指定的 String 在此实例中的第一个匹配项的索引。 

    语法:

    public int IndexOf (
        string value
    )

    返回值:

    如果找到该字符,则为 value 的索引位置;如果未找到该字符,则为 -1。如果 valueEmpty,则返回值为 0。 

    备注:

    索引编号从零开始。此方法使用当前区域性执行单词(区分大小写和区域性)搜索。该搜索从此实例的第一个字符位置开始,一直搜索到最后一个字符位置。

    using System;
    
    public class InsertTest {
        public static void Main() {
    
            string animal1 = "fox";
            string animal2 = "dog";
    
            string strTarget = String.Format("The {0} jumped over the {1}.", animal1, animal2);
    
            Console.WriteLine("The original string is:{0}{1}{0}", Environment.NewLine, strTarget);
    
            Console.Write("Please enter an adjective (or a group of adjectives) to describe the {0}: ==> ", animal1);
            string adj1 = Console.ReadLine();
    
            Console.Write("Please enter an adjective (or a group of adjectives) to describe the {0}: ==> ", animal2);    
            string adj2 = Console.ReadLine();
    
            adj1 = adj1.Trim() + " ";
            adj2 = adj2.Trim() + " ";
    
            strTarget = strTarget.Insert(strTarget.IndexOf(animal1), adj1);
            strTarget = strTarget.Insert(strTarget.IndexOf(animal2), adj2);
    
            Console.WriteLine("{0}The final string is:{0}{1}", Environment.NewLine, strTarget);
        }
    }

    5,String.Replace 方法

    重载列表:String.Replace (Char, Char)  String.Replace (String, String)  

    将此实例中的指定 String 的所有匹配项替换为其他指定的 String。 

    public string Replace (
        string oldValue,
        string newValue
    )

    参数

    oldValue

    要替换的 String

    newValue

    要替换 oldValue 的所有匹配项的 String

    返回值

    等效于此实例,但将 oldValue 的所有实例都替换为 newValueString

    备注:

    如果 newValue 为 空引用(在 Visual Basic 中为 Nothing),则移除 oldValue 的所有匹配项。

    此方法执行词搜索(区分大小写,区分区域性)以查找 oldValue

    如果 newValue 为 空引用(在 Visual Basic 中为 Nothing),则移除 oldValue 的所有匹配项。

    此方法执行词搜索(区分大小写,区分区域性)以查找 oldValue

    using System;
    
    public class ReplaceTest {
        public static void Main() {
    
            string errString = "This docment uses 3 other docments to docment the docmentation";
    
            Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString);
    
            // Correct the spelling of "document".
    
            string correctString = errString.Replace("docment", "document");
    
            Console.WriteLine("After correcting the string, the result is:{0}'{1}'",
                    Environment.NewLine, correctString);
        }
    }
    //
    // This code example produces the following output:
    //
    // The original string is:
    // 'This docment uses 3 other docments to docment the docmentation'
    //
    // After correcting the string, the result is:
    // 'This document uses 3 other documents to document the documentation'
    //

    6,String.Split();

    7,FindControl

    RadioButtonList rb = (RadioButtonList)gvcheck.Rows[i].FindControl("rbresult");
    TextBox txt = this.gvcheck.Rows[i].FindControl("txtpositionno") as TextBox;
     ((TextBox)gvcheck.Rows[i].FindControl("txtremrk")).Enabled = false;
     ((TextBox)gvcheck.Rows[i].FindControl("txtpositionno")).Enabled = false;
  • 相关阅读:
    字节码编程,Javassist篇四《通过字节码插桩监控方法采集运行时入参出参和异常信息》
    字节码编程,Javassist篇三《使用Javassist在运行时重新加载类「替换原方法输出不一样的结果」》
    字节码编程,Javassist篇二《定义属性以及创建方法时多种入参和出参类型的使用》
    字节码编程,Javassist篇一《基于javassist的第一个案例helloworld》
    CPU瞒着内存竟干出这种事
    可怕!CPU竟成了黑客的帮凶!
    完了!CPU一味求快出事儿了!
    如果平行宇宙也有编程语言
    你离黑客的距离,就差这20个神器了
    哈希表哪家强?几大编程语言吵起来了!
  • 原文地址:https://www.cnblogs.com/jonson1126/p/3046962.html
Copyright © 2011-2022 走看看