我有一个if
语句,它检查变量是否等于某个字符串。但是,我想检查字符串中是否有数字。事情是这样的:如何判断未知数字是否在字符串中?
if(thestring.equals("I, am awesome. And I'm " + Somehowgetifthereisanumberhere + " years old")) {
//Do stuff
}
或者更具体地说,其中X是未知号码,只知道有一个数字(任意数量)有:
String str = item.substring(item.indexOf("AaAaA" + x), item.lastIndexOf("I'm cool."));
如何做到这一点?
只需使用正则表达式。 – BackSlash
看着我..我认为这已被问:http://stackoverflow.com/questions/372148/regex-to-find-an-integer-within-a-string –