資料結構 筆記:KMP演算法的應用
阿新 • • 發佈:2018-11-14
成員函式 | 功能描述 |
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,