Last active
September 30, 2016 23:41
-
-
Save oleglomako/56d3d67cbea78b41530b3971ef0517c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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