Created
July 8, 2015 14:02
-
-
Save yishai-glide/fc360ff54daef3b2de9f 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
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