更新时间:2023-02-05 13:07:02
我假设您想在代码中执行此操作. api中没有任何东西可以对整个String数组进行文本匹配;您需要一次完成一项操作:
I assume that you want to do this in code. There's nothing in the api to do text matching on an entire String array; you need to do it one element at a time:
String[] androidStrings = getResources().getStringArray(R.array.android);
for (String s : androidStrings) {
int i = s.indexOf("software");
if (i >= 0) {
// found a match to "software" at offset i
}
}
当然,您可以使用Matcher和Pattern,或者如果您想知道匹配项在数组中的位置,可以使用索引对数组进行迭代.但这是一般的方法.
Of course, you could use a Matcher and Pattern, or you could iterate through the array with an index if you wanted to know the position in the array of a match. But this is the general approach.