How can one extract number of trailing zeros from String

I want to extract trailing zeros from a string for eg //8320987112741390144276341183223364380754172606361245952449277696409600000000000000 should yield 14 my approach was to first find the length of above string then subtract it by length of the stripped trailing zero string. I tried to find the later using BigDecimal stripTrailingZeros() method but it is only removing zeros after decimal

for eg

1200.000 is converted to 1200 by stripTrailingZeros() method but i want 12 as output

any idea how to solve this problem?

Jon Skeet
people
quotationmark

The simplest option would probably be to use String.replaceAll:

text = text.replaceAll("[0.]*$", "");

The $ makes sure it's only trimming the end of the string.

Note that if you start with "0" you'll end up with an empty string - think about what you want the result to be in that situation.

people

See more on this question at Stackoverflow