成员函数 | 功能描述 |
indexOf(s) | 查找子串s在字符串中的位置 |
remove(s) | 将字符串中的子串s删除 |
operator-(s) | 定义字符串减法 |
replace(s,t) | 将字符串中的子串s替换为t |
sub(i,len) | 从字符串中创建子串 |
子串查找(KMP算法的直接运用)
-int indexOf(const char* s) const
-int indexOf(const String& s)const
在字符串中将制定的子串删除
-String& remove(const char* s)
-String& remove(const String& s)
字符串的减法操作定义(operator -)
-使用remove实现字符串间的减法操作
·字符串自身不被修改
·返回产生的新串
String s1 = "somthing";
String s2 = s1 - "som" ;
cout << s1.str() << endl; //somthing
cout << s2.str() << endl; //thing
字符串中的子串替换
-String sub(int i,int len)const
·以i为起点取长度为len的子串
·子串提取下回编程字符串的本身状态
总结:
-字符串类是工程开发中必不可少的组件
-字符串中应该包含常用字符串操作函数
-增:insert,opertor + ,
-删:remove,operator -
-查:indexOf,
-改:replace,