I need to process some strings in Java. I know there is a
trim() method, but I need a Left Trim and a Right Trim .
How do I do this?
For now I'm looping through the string and stripping all whitespace from the beginning (until it hits a character) or from the end ( looping from the end to the beginning of the string ).
You can use regex:
String texto_filtrado = original.replaceAll("\\s+$", "");
String texto_filtrado = original.replaceAll("^\\s+", "");