字符串:string s = "1,2,3,4,5,"
1、用的最多的是Substring

2、用 RTrim,原来只用来删除最后的空格,也没有仔细看过其它的用法,才发现可以直接trim掉一些字符
s=s.ToString().RTrim(',')
s=s.TrimEnd(',')
//如果要删除"5,",则需要这么写
char[]MyChar={'5',','};
s=s.TrimEnd(MyChar);
//s="1,2,3,4"

扩展 删除空格
function trim(str){ //删除左右两端的空格 return str.replace(/(^s*)|(s*$)/g, ""); } function ltrim(str){ //删除左边的空格 return str.replace(/(^s*)/g,""); } function rtrim(str){ //删除右边的空格 return str.replace(/(s*$)/g,""); }
3、用TrimEnd,这个东西和RTrim差不多,区别是这个传递的是一个字符数组,而RTrim可以是任何有效的字符串





类似函数:
TrimStart,LTrim等
还有一个TrimToSize对提高性能有微弱的好处....
TrimStart,LTrim等
还有一个TrimToSize对提高性能有微弱的好处....
string.TrimEnd().Remove(string.Length - 2, 1)
string.Remove()
string.Remove()
参考1:http://blog.163.com/li_crane/blog/static/19502097201011281835796/