Java 中是否有与 C++ 的“std::string::find_first_of”等效的东西?
string string1( "This is a test string!");
int location = string1.find_first_of( "aeiou" );
//location is now "2" (the position of "i")
实现相同功能的最简单方法是什么?
编辑:建议的解决方案也必须适用于 Android。
不使用外部库:
String string = "This is a test string!";
String letters = "aeiou";
Pattern pattern = Pattern.compile("[" + letters + "]");
Matcher matcher = pattern.matcher(string);
int position = -1;
if (matcher.find()) {
position = matcher.start();
}
System.out.println(position); // prints 2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)