-
Notifications
You must be signed in to change notification settings - Fork 3
/
位置查找.cpp
62 lines (52 loc) · 1.4 KB
/
位置查找.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "位置查找.h"
//2句子去除标点符号 空格 求出汉字个数
void testfindback(string str, string chars, void callback(size_t)) {
string strstr = str;
string strchars = chars;
size_t pos = strstr.find_first_of(strchars);
if (pos != string::npos) {
callback(pos);
}
}
//返回位置
void myCallback(size_t index) {
cout << "位置" << index << endl;
}
void test05(string str, void callback(size_t)) {
string sworlds = str;
size_t num = sworlds.length();
// int nums = static_cast<int>(sworlds.length());
string chars = "abcefgiklmopqrstuvwxyz!@#$%^&*-=\"?[]~|()_+'/{}`<>\\;:12345790 ";
testfindback(sworlds, chars, callback);
}
//字符串查找
/* string str1 = "好大啊";
string chars1 = "你们真的好吗?是不是真的啊?"
返回2
*/
void testfind(string str, string chars) {
string strstr = str;
string strchars = chars;
size_t pos = strstr.find_first_not_of(strchars);
if (pos != string::npos) {
cout << pos << endl;
}
else {
cout << "没有找到" << endl;
}
}
/*string str1 = "哈哈哈哈啊哈哈";
string chars1 = "你们真的好吗?是不是真的啊?";
返回8
*/
void testfind01(string str, string chars) {
string strstr = str;
string strchars = chars;
size_t pos = strstr.find_first_of(strchars);
if (pos != string::npos) {
cout << pos << endl;
}
else {
cout << "没有找到" << endl;
}
}