我有一個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 –