Reputation: 4660
How do I change 38k to 38000? or 43k to 48000 etc
I tried this
String s0=toClean.replaceAll("[0-9]k", "[0-9]000");
But its wrong. It changes 38k to 309000
Upvotes: 0
Views: 73
Reputation: 19005
Not only one digit, but multiple (so add +
). Also, you should capture that number and return it with the capture group 1 ($1
) and check if there's nothing else after k
(e.g. so as 38kabc
wouldn't be valid)
String s0=toClean.replaceAll("([0-9]+)k\\b", "$1000");
Upvotes: 4