C# 字符串的截取和替换

1、取字符串的前n个字符

(1)string str1=str.Substring(0,n);

(2)string str1=str.Remove(i,str.Length-n);

 

2、去掉字符串的前n个字符

string str1=str.Remove(0,n);

string str1=str.SubString(n);

 

3、从右边开始取n个字符:

string str1=str.SubString(str.Length-n);

string str1=str.Remove(0,str.Length-n);

 

4、从右边开始去掉n个字符:

string str1=str.Substring(0,str.Length-n);

string str1=str.Remove(str.Length-n,n);

 

5、如果字符串中有"abc"则替换成"ABC"
   str=str.Replace("abc","ABC");

 

6、c#截取字符串最后一个字符的问题

str1.Substring(str1.LastIndexOf(",")+1);

 

7、C# 截取字符串最后一个字符

str = str.Substring(str.Length-1, 1);

posted @ 2016-08-16 21:08  Adolf_Ye  Views(46544)  Comments(0Edit  收藏  举报