D Deleted User Guest Apr 2, 2019 #2 You could do it with a regex Code: String line = "te5t"; Pattern r = Pattern.compile(".*[0-9].*"); Matcher m = r.matcher(line); if (m.find( )) { System.out.println("It matched"); }
You could do it with a regex Code: String line = "te5t"; Pattern r = Pattern.compile(".*[0-9].*"); Matcher m = r.matcher(line); if (m.find( )) { System.out.println("It matched"); }
scary alien not really so scary VIP Member Apr 2, 2019 #3 +1 to LV I've also used this method before: public static boolean isNumeric(String str) { try { Double.parseDouble(str); return true; } catch(NumberFormatException e){ return false; } } (taken from the excellent site: https://stackoverflow.com/questions/1102891/how-to-check-if-a-string-is-numeric-in-java that also has a lot more/other suggestions on how to accomplish this) Cheers!
+1 to LV I've also used this method before: public static boolean isNumeric(String str) { try { Double.parseDouble(str); return true; } catch(NumberFormatException e){ return false; } } (taken from the excellent site: https://stackoverflow.com/questions/1102891/how-to-check-if-a-string-is-numeric-in-java that also has a lot more/other suggestions on how to accomplish this) Cheers!
D Deleted User Guest Apr 2, 2019 #4 scary alien said: +1 to LV Click to expand... Thanks Scary. I have to give 0.5 of that to @GameTheory who put the idea of regex in my head with an answer to a recent question.
scary alien said: +1 to LV Click to expand... Thanks Scary. I have to give 0.5 of that to @GameTheory who put the idea of regex in my head with an answer to a recent question.