创建String对象的方式
1、通过给String变量指定一个字符串
2、通过使用String类构造函数
3、通过使用字符串串联运算符(+)
4、通过检索属性或者调用一个返回字符串的方法
5、通过格式化方法来转换一个值或对象为它的字符串表示形式
String类的属性
Chars : 在当前String对象中获得指定位置的char对象。
Length : 在当前的String对象中获取字符数
String类的方法
1、public static int Compare(string strA,string strB) : 比较两个指定的string对象,并返回一个表示他们在排序顺序中相对于位置的整数。该方法区分大小写。
2、public static int Compare( string strA, string strB, bool ignoreCase ) : 比较两个指定的string对象,并返回一个表示他们在排序顺序中相对于位置的整数。但是如果布尔参数为真时,该方法不区分大小写。
3、public static string Concat( string str0, string str1 ) : 连接两个 string 对象。
4、public bool Contains( string value ) : 返回一个表示指定string对象是否出现在字符串中的值
5、public static string Copy( string str ) : 创建一个与指定字符串具有相同值的新的string对象
6、public void CopyTo( int sourceIndex, char[] destination, int destinationIndex, int count ) : 从string对象的指定位置开始复制指定数量的字符串到Unicode字符串数组中的指定位置
参数介绍 :sourceIndex : 要复制的此实例中第一个字符串的索引
destination : 此实例中的字符所复制到的字符串数组
destinationIndex : 所复制到的字符数组中的索引(注:所复制到的数组不会调整大小,请保证它的足够数量元素,否则报错)。
count : 此实例中复制到destination的字符数。
7、public bool EndsWith( string value ) : 判断string对象的结尾是否匹配指定的字符串
8、public bool Equals( string value ) : 判断当前的string对象是否与指定的string对象具有相同的值
9、public static string Format( string format, Object arg0 ) : 把指定字符串中一个或多个格式项替换为指定对象的字符串表示形式。
10、public int IndexOf() : 指定字符或字符串在此实例中的第一个匹配项的从零开始的索引。如果未在此实例中找到该字符或者字符串,则此方法返回-1.
11、public int IndexOfAny() : 指定字符数组中的任意字符在此实例中第一个匹配项的索引。如果未在此实例中找到数组中的字符,则此方法返回-1.
12、public string Insert (int startIndex, string value) : 返回一个新的字符串,在此实例中的指定的索引位置插入指定的字符串。
13、public static bool IsNullOrEmpty( string value ) : 指示指定的字符串是否为null或者是否为空的字符串。
14、public static string Join( string separator, string[] value ) : 连接一个字符串数组中的所有元素,使用指定的分隔符分割每个元素。
15、public int LastIndexOf( ) : 返回字符或者字符串在此实例中的最后一个匹配项的从零开始的索引位置。如果未在此实例中找到该字符或字符串,则此方法返回-1.
16、public string Remove( int startIndex,int count ) : 从当前字符串的指定位置开始移除指定数量的字符串,(如果第二个参数为空则一直到最后),并返回字符串。
17、public string Replace( char oldChar, char newChar ) : 返回一个新字符串,其中已将当前字符串中的指定字符或字符串的所有匹配项替换为其他指定的字符或字符串。
18、public string[] Split( params char[] separator ) : 返回的字符串数组包含此实例中的子字符串(由指定字符串或字符数组的元素分割)
19、public bool StartsWith( string value ) : 判断字符串实例的开头是否匹配指定的字符串
20、public char[] ToCharArray() : 返回一个带有当前string对象中所有字符的字符数组
21、public string ToLower() : 把字符串转换为小写并返回。
public string ToUpper() : 把字符串转换为大写并返回。
22、public string Trim() : 移除当前string对象中的所有前导空白字符和后置空白字符(只能移除前端和后端的空格,不能移除中间的空格)
23、public string Substring(int startIndex,int length) : 子字符串从指定的字符位置开始且具有指定的长度。(如果第二个参数为空,则从指定位置到最后)