## 替换字符串函数:replace()
replace("要替换的内容",要替换的位置,“替换成的东西”)
replace("要替换的指定位置",要替换的长度,“替换成的东西”)
eg:line="this is a ab ,not bad"
replace(line.find("ab"),1,"") -- 把line字符串中第一个位置的ab换成空
line.replace(line.begin(),line.begin()+6,""); -- 把line从begin开始的6个字符替换成空
line.replace(0, 5, str); //用str替换从指定位置0开始长度为5的字符串
## begin() end()
# line.begin() -- 返回字符串的首位字符的下标位置
-- 注意:只返回首位,不是返回首个出现的字符?
# line.end() -- 返回字符串中的末尾的下标位置+1,即下标位置多了一个位置
-- 若想得到末尾字符的下标位置,需要end()-1
## 插入 insert(索引,"插入的数据")
string site = "hello";
site.insert(2,"L") -- 插入索引为2的位置,输出heLllo
## 两个字符串进行比较 str1.compare(str2)
## 交换字符串 swap(str1, str2)
## str1.size()
## str1.length()
c++ 常用字符串函数
xzal122024-10-16 22:55
相关推荐
clint4563 天前
C++进阶(1)——前景提要夜悊3 天前
C++代码示例:进制数简单生成工具郝学胜_神的一滴3 天前
CMake 021: IF 条件判据详诠_wyt0013 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解玖玥拾3 天前
C/C++ 数据结构(七)栈、容器适配器один but you3 天前
constexpr函数凡人叶枫4 天前
Effective C++ 条款41:了解隐式接口和编译期多态凡人叶枫4 天前
Effective C++ 条款42:了解 typename 的双重意义小胖xiaopangss4 天前
BRpc使用-森屿安年-4 天前
63. 不同路径 II