我有话要说
"unspecified"
,我想在字符串中搜索这个词,即:"777 unspecifieduser 330"
我想知道这个字符串有没有“unspecified”字样?
在 java 中,我会欣赏细节
提前致谢
最佳答案
使用 String.contains
方法。
String str = "777 unspecifieduser 330";
if (str.contains("unspecified")) {
// ...
}
一个稍微更通用的方法是使用正则表达式:
"777 unspecifieduser 330".matches(".*unspecified.*")
如果您对子字符串出现的位置感兴趣。使用 String.indexOf
方法。
关于java - 在java中读取String中的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6340595/