C#删除字符串最后一个字符的几种方法
1字符串:string s = "1,2,3,4,5,"
2 目标:删除最后一个 ","
3
4 方法:
5 1、用的最多的是Substring,这个也是我一直用的
6 s = s.Substring(0,s.Length - 1)
7 2、用TrimEnd,这个东西传递的是一个字符数组
8
9 s=s.TrimEnd(',')
10 //如果要删除"5,",则需要这么写
11 char[] MyChar = {'5',','};
12 s = s.TrimEnd(MyChar);
13
14 //s = "1,2,3,"
15 3、用Remove
16 string a = "123";
17 a = a.Remove(a.Length - 1,1); //移除掉","