Skip to content

Instantly share code, notes, and snippets.

@oleglomako
Last active September 30, 2016 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleglomako/56d3d67cbea78b41530b3971ef0517c6 to your computer and use it in GitHub Desktop.
Save oleglomako/56d3d67cbea78b41530b3971ef0517c6 to your computer and use it in GitHub Desktop.
/**
* Extract digit from string
*/
public class Test {
public static void main(String[] args) {
String str = "0b1100100";
str = new String(str.replaceAll("\\D+", ""));
int n = Integer.parseInt(str, 2);
System.out.println(n);
// This work if your number has a decimal point
String str2 = "foo 2.36 bar";
str2 = str2.replaceAll("[^\\.0123456789]","");
System.out.println(str2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment