In this case (when the token defining it as a number is at the beginning):
final String input = "Rp.1.000.000.000";
int value = 0;
String token = "Rp";
if (input.contains(token))
value = Integer.parseInt(input.replaceAll("[^012456789]", ""));
Explanation
.replaceAll("[^012456789]", "")
removes all non-numeric chars (R
, P
and .
in this case). So the leftover is a String
only containing digits which can easily be converted into an int
by using Integer.parseInt()
solved Get data type from String when the String have symbol [closed]