std::string replace详解

来源:互联网 发布:c语言成绩管理系统设计 编辑:程序博客网 时间:2024/05/28 15:30

string类的替换函数:

std::string replace详解

string &replace(int p0, int n0,const char *s);
//删除从p0开始的n0个字符,然后在p0处插入串s。如果从p0开始的n0个字符已经超过了字符串的最大长度,则将字符串p0后续的所有字符都删除,然后再插入字符串s。

string &replace(int p0, int n0,const char *s, int n);
//删除p0开始的n0个字符,如果从p0开始的n0个字符已经超过了字符串的最大长度,则将字符串p0后续的所有字符都删除,然后在p0处插入字符串s的前n个字符。如果字符串的长度小于n,则将字符串s所有的字符插入到原始字符串中。

string &replace(int p0, int n0,const string &s);
//删除从p0开始的n0个字符,如果从p0开始的n0个字符已经超过了字符串的最大长度,则将字符串p0后续的所有字符都删除,然后在p0处插入串s

string &replace(int p0, int n0,const string &s, int pos, int n);
//删除p0开始的n0个字符,如果从p0开始的n0个字符已经超过了字符串的最大长度,则将字符串p0后续的所有字符都删除,然后在p0处插入串s中从pos开始的n个字符。如果s从pos开始到结尾没有n个字符,则将s从pos开始的所有字符都插入到原始字符串中。

string &replace(int p0, int n0,int n, char c);
//删除p0开始的n0个字符,如果从p0开始的n0个字符已经超过了字符串的最大长度,则将字符串p0后续的所有字符都删除,然后在p0处插入n个字符c

string &replace(iterator first0, iterator last0,const char *s);
//把[first0,last0)之间的部分替换为字符串s。

string &replace(iterator first0, iterator last0,const char *s, int n);
//把[first0,last0)之间的部分替换为s的前n个字符

string &replace(iterator first0, iterator last0,const string &s);
//把[first0,last0)之间的部分替换为串s

string &replace(iterator first0, iterator last0,int n, char c);
//把[first0,last0)之间的部分替换为n个字符c

string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last);
//把[first0,last0)之间的部分替换成[first,last)之间的字符串

原创粉丝点击