String: string s = "1,2,3,4,5,"
Goal: Delete the last ","
Method:
1, the most used is substring, this is what I have been using
S=s.substring (0,s.length-1)
2, with RTrim, this I originally only know to remove the last space, also did not carefully read the other usage, only found that can be directly trim off some characters
S=s.tostring (). RTrim (', ')
3, with trimend, this thing and RTrim almost, the difference is that this pass is a character array, and RTrim can be any valid string
S=s.trimend (', ')
If you want to delete "5," you need to write this
char[]mychar={' 5 ', ', '};
S=s.trimend (MyChar);
S= "1,2,3,4"
Similar functions:
Trimstart,ltrim, etc.
There is also a trimtosize that has a slight benefit in improving performance ....
String. TrimEnd (). Remove (String. Length-2, 1)
String. Remove ()
This article is from the "Silent http://www.51pro.net" blog, please be sure to keep this source http://ruiwen.blog.51cto.com/8852761/1706187
Several ways JavaScript removes the last character of a string