Java与C++的“std::string::find_first_not_of”相当

Java与C++的“std::string::find_first_not_of”相当,java,string,Java,String,C++的std::string::find_first_not of是否有Java等价物 我有: 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_,我使用此函数: public static int findFirstOf(

C++的std::string::find_first_not of是否有Java等价物

我有:

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_,我使用此函数:

    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;
    }

也许这里需要一些改变?

我想你可以用一种非常简单的方式来写:

静态int-findFirstNotOfString searchIn、字符串searchFor、int-searchFrom{ char[]chars=searchFor.toCharArray; 布尔发现; 对于int,i=searchFrom;i我指的是所描述的函数。

首先,您可能想解释find_first_not_of的作用。我怀疑在正则表达式中打开字符类后包含^I可以满足您的要求,但我不知道find_first_not of的作用,我只是根据名称猜测。首先,您的findFirstOf有问题。请尝试findFirstOfx,^y,0;。你需要避开那些字母。此外,您的位置参数目前有点无用和误导。@FedericoklezCulloca如果我认为正确的话,那么std::find_first_not_of会找到与传递的字符序列中的任何字符都不相等的第一个字符。也许Java有一些库,如Apache Commons或Google Guava可以提供帮助?谢谢,我现在试试我有一个问题,在这里你创建了两个布尔值,它是否是相同的变量?还有一个问题,参数pos在哪里?在原始std::find_first_not_of std::string str中,size\u t pos;has string-它的searchFor和pos,从哪个位置进行检查。我知道该怎么做。这不难添加。无论如何,我可以再编辑一次。请编辑,因为我的脑袋不太好,我真的很累,但我需要完成。你已经通过代码给出了你的方法。如果有对代码的解释和关于解决问题的其他方法的解释,那么解决方案将更有帮助。
static int findFirstNotOf(String searchIn, String searchFor, int searchFrom) {
   // char[] chars = searchFor.toCharArray();
    boolean found;
    char c;
    for (int i = searchFrom; i < searchIn.length(); i++) {
        found = true;
       // for (char c : chars) {
        c = searchIn.charAt(i);
            System.out.printf("s='%s', idx=%d\n",c,searchFor.indexOf(c));
            if (searchFor.indexOf(c) == -1) {
                found = false;
            }
      //  }
        if (!found) {
            return i;
        }
    }
    return -1;
}

public static void main(String[] args){
    String str =  "look for non-alphabetic characters...";

     int  found = findFirstNotOf(str,"abcdefghijklmnopqrstuvwxyz ",0);

      if (found!=str.length()) {
        System.out.print("The first non-alphabetic character is " + str.charAt(found));
        System.out.print(" at position " + found + '\n');
      }
}