資料結構 筆記:字串類的建立(下)
阿新 • • 發佈:2018-11-14
字串類中的常用成員函式
成員函式 | 功能描述 |
operator[](i) | 操作符過載函式,訪問指定下標的字元 |
startWith(s) | 判斷字串是否以s開頭 |
endOF(s) | 判斷字串是否以s結束 |
insert(i,s) | 在字串的位置i出插入s |
trim() | 去掉字串兩端的空白 |
過載陣列訪問操作符[]
-char& operator[](int i);
-char operator[](int i) const;
注意事項
當i的取值不合法時,丟擲異常
·合法範圍:(0 <= i) && (i < m_length)
判斷是否以指定字串開始或結束
-bool startWith(const char* s) const;
-bool startWith(const String& s)const;
-bool endOf(const char* s)const;
-bool endOf(const String& s)const;
在指定位置出插入字串
-String& insert(int i,const char* s);
-String& insert(int i,const String& s);
去掉字串兩端的空白字元
-String& trim();