trim trailing comma
Posted on 2006-11-30
Hi all, i have the below code that trims trailing chars off of a string.
String a = "a,b,c,d,e,";
String b = a.trim().substring(0, a.length() - 1);
I intended to use it to strip "," off of my strings. the only problem is if there is no trailing comma, or no entry at all it throws a "String index out of range: -1" error.
IS there a condition or something i can use to fix that?