在java中读取String中的字符?

zia*_*zia 1 java string char

我有一个字

"未指定"

,我想用字符串搜索这个单词,即: "777 unspecifieduser 330"

我想知道这个字符串是否有"未指定"字样?

在java中,我会很感激细节

提前致谢

aio*_*obe 7

使用该String.contains方法.

String str = "777 unspecifieduser 330";
if (str.contains("unspecified")) {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

一种更为通用的方法是使用正则表达式:

"777 unspecifieduser 330".matches(".*unspecified.*")
Run Code Online (Sandbox Code Playgroud)

如果您对子字符串出现的位置感兴趣.使用该String.indexOf方法.