Hi I have a string in java that goes like this:
"742706t000gf4604008264468468400000000000000000000000"
How would I remove all the trailing 0's at the end but leaving the ones in between?
Thanks!
You can use a regex with the "$" character that indicates string's end, and the String.replaceAll() method
str = str.replaceAll("0+$", "")
str = str.replaceAll("0+$", ""); works for me.str.replaceAll("0+$", "") to a variable - it creates a NEW string without the zeros, and it does NOT modify the old string
value.replaceAll("0+$", "");or with commons-lang.