Skip to content

Instantly share code, notes, and snippets.

@yishai-glide
Created July 8, 2015 14:02
Show Gist options
  • Save yishai-glide/fc360ff54daef3b2de9f to your computer and use it in GitHub Desktop.
Save yishai-glide/fc360ff54daef3b2de9f to your computer and use it in GitHub Desktop.
public void parseString(String str) {
if(TextUtils.isEmpty(str)) {
// nothing here
return;
}
String[] words = str.split(" ");
StringBuilder sentence = new StringBuilder(str.length());
int l_integer;
double l_double;
for(String word : words) {
if(TextUtils.isDigitsOnly(word)) {
// try to parse int
try {
l_integer = Integer.parseInt(word);
}catch (NumberFormatException e) {
//attempt to parse double
l_double = Double.parseDouble(word);
}
} else {
sentence.append(word + " ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment