Java 中是否有与 C++ 的“std::string::find_first_not of”等效的东西?
我有:
std::string path = "some path";
std::string eol = "some text";
size_t nextLinePos = path.find_first_not_of("\r\n", eol);
如何在 Java 上执行此操作?
Ps:对于 std::find_first_of
我使用这个函数:
public static int findFirstOf(String findIn, String letters, int position)
{
Pattern pattern = Pattern.compile("[" + letters + "]");
Matcher matcher = pattern.matcher(findIn);
if (matcher.find())
{
position = matcher.start();
}
return position;
}
也许这里需要改变一些东西?
最佳答案
您可以用非常简单的方式编写:
static int findFirstNotOf(String in, String notOf, int from) {
for (int i = from; i < in.length(); ++i) {
if (notOf.indexOf(in.charAt(i)) == -1) {
return i;
}
}
return -1;
}
我指的是描述的函数 here .
关于C+ 的 Java 等效项 +'s “std::string::find_first_not_of”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60710385/