What would be the best way to get the first two numbers of a string?
I can do it like this:
public static String getFirstTwoNumbersOfString(String s){
if(s == null)
return "";
String numbers = "0123456789";
String result = "";
for(int i=0; i<s.length() && result.length()<2; i++){
String c = String.valueOf(s.charAt(i));
if(numbers.contains(c)){
result += c;
}
}
return result;
}
But I think there must be a better way, more concise and with better performance.