Extracting Only Integers From the String
Example:
public class string_to_int {
public static void main(String[] args) {
String s ="this is 100 rupees";
//D is digit here and " " for storing integer value
int num=Integer.parseInt(s.replaceAll("\\D", ""));
System.out.println(num);
}
}
Output:
100
No comments:
Post a Comment