zoukankan      html  css  js  c++  java
  • 好文收藏_关于find_first_not_of函数

    原文地址:http://blog.csdn.net/ffjbq/article/details/7611255


    这两个方法都是查找与()中指定的字符串中任意一个字符都不相符的字符的位置地址,而不是返回的是与()中制定的字符串完全匹配的字符串的首地址

    find_first_not_of()

    语法:

      size_type find_first_not_of( const basic_string &str, size_type index = 0 );
      size_type find_first_not_of( const char *str, size_type index = 0 );
      size_type find_first_not_of( const char *str, size_type index, size_type num );
      size_type find_first_not_of( char ch, size_type index = 0 );
    

    find_first_not_of()函数:

    • 在字符串中查找第一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops
    • 在字符串中查找第一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始,最多查找num个字符。如果没找到就返回string::nops
    • 在字符串中查找第一个与ch不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops
    size_t find_first_not_of ( const string& str, size_t pos = 0 ) const;
    size_t find_first_not_of ( const char* s, size_t pos, size_t n ) const;
    size_t find_first_not_of ( const char* s, size_t pos = 0 ) const;
    size_t find_first_not_of ( char c, size_t pos = 0 ) const;
    Find absence of character in string

    Searches for the first character in the object which is not part of eitherstr,s or c, and returns its position.

    When pos is specified the search only includes characters on or after positionpos, ignoring any content in the previous character positions.

    // string::find_first_not_of
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main ()
    {
      string str ("look for non-alphabetic characters...");
      size_t found;
    
      found=str.find_first_not_of("abcdefghijklmnopqrstuvwxyz ");
      if (found!=string::npos)
      {
        cout << "First non-alphabetic character is " << str[found];
        cout << " at position " << int(found) << endl;
      }
    
      return 0;
    }
    size_t find_first_of ( const string& str, size_t pos = 0 ) const;
    size_t find_first_of ( const char* s, size_t pos, size_t n ) const;
    size_t find_first_of ( const char* s, size_t pos = 0 ) const;
    size_t find_first_of ( char c, size_t pos = 0 ) const;

    Find character in string

    Searches the string for any of the characters that are part of eitherstr,s or c, and returns the position of the first occurrence in the string.

    When pos is specified the search only includes characters on or after positionpos, ignoring any possible occurrences at previous character positions.

    Notice that for a match to happen it is enough that one of the characters matches in the string (any of them). To search for an entire sequence of characters usefind instead.

    Return Value

    The position of the first occurrence in the string of any of the characters searched for.
    If the content is not found, the member value npos is returned.

    Example

    // string::find_first_of
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main ()
    {
      string str ("Replace the vowels in this sentence by asterisks.");
      size_t found;
    
      found=str.find_first_of("aeiou");
    // string::npos 表示string的最后一个位置的地址
      while (found!=string::npos)
      {
        str[found]='*';
        found=str.find_first_of("aeiou",found+1);
      }
    
      cout << str << endl;
    
      return 0;
    }
     
  • 相关阅读:
    oracle创建函数和调用存储过程和调用函数的例子(区别)
    oracle存储过程的创建和使用
    oracle恢复已删除数据
    存储管理工具StorageExplorer的基本使用
    Azure CLI对ASM,ARM资源的基本操作
    Windows系统安装Azure CLI
    Azure Powershell对ASM资源的基本操作
    Azure Powershell对ARM资源的基本操作
    安装Windows Azure Powershell
    Linux虚拟机之间实现密钥登陆
  • 原文地址:https://www.cnblogs.com/xf666/p/7087052.html
Copyright © 2011-2022 走看看