字符串操作集合

1、字符串长度截取操作

string.Substring(index)   // 取 index 后的字符,包括index位置,默认起始为 0;

//如:

str=abcd;  

string s = str.Substring(2);

s=cd;

string.Substring(int index,int length)   //index:开始位置,从0开始 length:你要取的子字符串的长度

//如
string s=str.Substring(1,2);
s=bc

2、 特定字符串分割   (split)

string str=a+b+c+d+e;
string[] s=str.split('+');
s=[a,b,c,d,e];

//list存储
ArrayList numlist = new ArrayList();
foreach (string str in s)
{
    numlist.Add(str);
}

3、 字符串替换  Replace

//将单引号转成双引号
string s = "a said 'b is c','c b is e',a is smile";//这里无法修改了
string c = s.Replace("\'", "\"");//  \ 为转义符号,或者为 /

猜你喜欢

转载自blog.csdn.net/qq_21419015/article/details/81391392
今日推荐