首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_string::find_first_not_of

size_type find_first_not_of( const basic_string& str, size_type pos = 0 ) const;

(1)

size_type find_first_not_of( const CharT* s, size_type pos, size_type count ) const;

(2)

size_type find_first_not_of( const CharT* s, size_type pos = 0 ) const;

(3)

size_type find_first_not_of( CharT ch, size_type pos = 0 ) const;

(4)

size_type find_first_not_of( std::basic_string_view<CharT, Traits> sv, size_type pos = 0) const

(5)

(since C++17)

在给定的字符序列中,查找第一个字符不等于任何一个字符。搜索只考虑间隔。[pos,,,size()29%。如果该字符不在间隔中,npos会被归还。

1%29发现第一个字符不等于str...

2%29发现第一个字符与第一个字符中的任何字符都不相等。count所指向的字符串的字符。s...s可以包含空字符。

3%29查找第一个字符等于字符串中的第一个字符。s字符串的长度由第一个空字符决定。

4%29发现第一个字符不等于ch...

5%29发现第一个字符不等于sv...

在所有情况下,都通过调用Traits::eq...

参数

str

-

string identifying characters to search for

pos

-

position for the seach to start from

count

-

length of character string identifying characters to search for

s

-

pointer to a character string identifying characters to search for

ch

-

character identifying characters to search for

sv

-

std::basic_string_view identifying the characters to search for

返回值

已发现字符的位置或npos如果找不到这样的角色。

例外

1-4) (none)

(until C++11)

1,4) noexcept specification: noexcept 2,3) (none)

(since C++11)(until C++14)

1) noexcept specification: noexcept 2,3,4) (none)

(since C++14)

5) noexcept specification: noexcept

(since C++17)

二次

代码语言:javascript
复制
#include <string>
#include <iostream>
 
int main() {
    std::string to_search = "Some data with %MACROS to substitute";
 
    std::cout << "Before: " << to_search << '\n';
 
    auto pos = std::string::npos;
    while ((pos = to_search.find('%')) != std::string::npos) {
        // Permit uppercase letters, lowercase letters and numbers in macro names
        const auto after = to_search.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", pos + 1);
 
        // Now to_search[pos] == '%' and to_search[after] == ' ' (after the 'S')
 
        if(after != std::string::npos)
            to_search.replace(pos, after - pos, "some very nice macros");
    }
 
    std::cout << "After: " << to_search << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
Before: Some data with %MACROS to substitute
After: Some data with some very nice macros to substitute

二次

另见

find

find characters in the string (public member function)

rfind

find the last occurrence of a substring (public member function)

find_first_of

find first occurrence of characters (public member function)

find_last_of

find last occurrence of characters (public member function)

find_last_not_of

find last absence of characters (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券