Remove trailing zeros from string java -


this question has answer here:

although have seen question similar 1 asked quite few times, mean remove trailing zeroes.

i convert like

"1903895810000" 

to

"190389581" 

i looking string.replace() solution

simple regexp replaceall it.

string s = "1903895810000"; system.out.println(s.replaceall("0+$", "")); 

[edit]:

s.replace(0, "") not work here, because remove zeros string, can't use it. so, here used replaceall, uses regular expressions match replacement string. simple regexp 0+$ matches number of zeros 0+ followed end-of-string $, "some zeroes @ end".


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -