How can I trim characters in Java? e.g.
String j = “joejill”.Trim(new char[] {“”});
j should be
"joejill"
String j = “jackjoejill”.Trim("jack");
etc
Apache Commons has a great StringUtils class (org.apache.commons.lang.StringUtils). In StringUtils there is a strip(String, String) method that will do what you want.
StringUtils
strip(String, String)
I highly recommend using Apache Commons anyway, especially the Collections and Lang libraries.
1.4m articles
1.4m replys
5 comments
57.0k users