字符串:string s = "1,2,3,4,5,"
目标:删除最后一个 ","
方法:
1、用的最多的是Substring,这个也是我一直用的
s = s.Substring(0,s.Length - 1)
2、用TrimEnd,这个东西传递的是一个字符数组
s=s.TrimEnd(‘,‘)
//如果要删除"5,",则需要这么写
char[] MyChar = {‘5‘,‘,‘};
s = s.TrimEnd(MyChar);
//s = "1,2,3,"
3、用Remove
string a = "123";
a = a.Remove(a.Length - 1,1); //移除掉","
原文地址:https://www.cnblogs.com/lbjcoder/p/8472767.html
时间: 2024-10-17 21:09:36