c++ 常用字符串函数

复制代码
 ## 替换字符串函数: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()
相关推荐
blasit2 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_3 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星3 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛5 天前
delete又未完全delete
c++
端平入洛6 天前
auto有时不auto
c++
哇哈哈20217 天前
信号量和信号
linux·c++
多恩Stone7 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马7 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝7 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
weiabc7 天前
printf(“%lf“, ys) 和 cout << ys 输出的浮点数格式存在细微差异
数据结构·c++·算法