属性// public char this [ int index] { get ;} string str1 = "Test" ; for ( int ctr = 0; ctr <= - 1; ctr++ ) ( "{0} ", str1[ctr]); 属性 public int Length { get ;} // Sample for using System; class Sample { public static void Main() { string str = "abcdefg" ; ( "1) The length of '{0}' is {1}" , str, ); ( "2) The length of '{0}' is {1}" , "xyz" , "xyz" .Length); }} /* This example produces the following results: 1) The length of 'abcdefg' is 7 2) The length of 'xyz' is 3 */比较 pare // 比较大小 S tring str1= " 你好";S tring str2= " 你好吗"; (pare(str1,str2));//-1 (pare(str1,str1));//0 (pare(str2,str1));//1 pareT0 // 比较大小 String str1= " 你好"; String str2= " 你好吗"; Console .WriteLine(pareTo(str2)); //-1, 该形式不能重载 // 两字符串是否相同// 有两种重载方式; String str1= "1" ; String str2= "1" ; Console .WriteLine( String .Equals(str1,str2)); //True Console .WriteLine((str2)); //True Console .ReadKey(); 定位 sWith // 判断一个字符是否以另一字符串开头和结尾 String str1= "1" ; String str2= "1" ; Console .WriteLine(( "5" )); //False Console .WriteLine(( "1" )); //True Console .ReadKey(); // 字符或子串第一次出现的位置
C# String类 来自淘豆网m.daumloan.com转载请标明出处.