#include<iostream>
#include<string>
using namespace std;
//string字符串查找和替换
void test1() {
//查找
string str1 = "abcdefcd";
//查到返回查到的位置 查不到返回-1
int pos=str1.find("cd");
cout << "pos=" << pos<<endl;
//rfind先查最右边的 下标和find一样
int pos1= str1.rfind("cd");
cout << "pos1=" << pos1 << endl;
}
void test2() {
//替换
string str1 = "abcdefg";
string str2 = str1.replace(1, 3, "1111");
cout << str2 << endl;
}
int main() {
test1();
test2();
system("pause");
return 0;
}
string字符串查找和替换
最新推荐文章于 2024-07-25 09:47:19 发布