C#中String类方法汇总

来源:互联网 发布:手机淘宝没有删除评价 编辑:程序博客网 时间:2024/04/28 01:25

以下对C#中string类的方法进行汇总:

1.string (char[])      使用指定的字符串数组构建一个新的string对象

 

2.int Compare(string a,string b,bool case)     比较字符串a,b,case为true时表示不区分大小写。当a>b返回正数,当a<b返回负数,a=b返回0

 

3. bool EndsWith(string)         确定当前字符串是否以指定的字符串结尾

 

4. bool StartsWith(string)         确定当前字符串是否以指定的字符串开头

 

5.int IndexOf()               返回指定的字符或字符串在当前字符串中的位置

 

6.int  LastIndexOf()        返回指定字符或字符串的最后一个匹配项位置

 

7.string Insert(int,string)         在当前的字符串中插入一个指定的字符串

 

8.string Replace(string,string)   字符串替换

 

9.string Remove(int,int)               从指定位置开始删除指定个数的字符

 

10. ToUpper()    ToLower()           字符串大小写转换

 

11.string  SubString(int,int)          返回从指定位置开始指定个数的字符串

 

下面举个例子对个别方法进行说明:

string  str1=“Hello";

string srr2="World";

string Upper,str3;

Upper=str1.Upper();     ///将str1转换为大写

str3=str1.Insert(str1.Length,str2);    /// str3的内容为HelloWorld