C#去除字符串

2017年8月13日 1107 1

举例:

string test = "a,b,c,d,e,f,"

去除最后一个字符:“,”
方法:
1、用Substring

test  = test.Substring(0,test.Length - 1)

2、用TrimEnd,这个东西传递的是一个字符数组

test=test.TrimEnd(',')

3、用Remove

test = test.Remove(test.Length - 1,1);

去除多个字符:

//去除"f,"
char[] RemoveChar = {'f',','};
test = test.TrimEnd(RemoveChar);

最后输出:

test = "a,b,c,d,e,"