補碼
1、bool qstring::startswith // 字串以xx開頭,返回true,第二個引數可以設定大小寫敏感
qstring str = "bananas";2、bool qstring::endswith // 字串以xx結尾,返回false,第二個引數可以設定大小寫敏感str.startswith("ban"); // returns true
str.startswith("car"); // returns false
qstring str = "bananas";3、qstring qstring::trimmed() // 返回前後沒有空格的字串str.endswith("anas"); // returns true
str.endswith("pple"); // returns false
qstring str = " lots\t of\nwhitespace\r\n ";4、qstring &qstring::remove(int position, int n) // 指定位置開始刪除n個字元,返回該字元引用str = str.trimmed();
// str == "lots\t of\nwhitespace"
qstring s = "montreal";5、int qstring::indexof() // 返回從指定位置開始第一次出現的索引位置,未找到返回-1。第二個引數可以設定大小寫敏感s.remove(1, 4);
// s == "meal"
qstring x = "sticky question";6、int qstring::lastindexof()qstring y = "sti";
x.indexof(y); // returns 0
x.indexof(y, 1); // returns 10
x.indexof(y, 10); // returns 10
x.indexof(y, 11); // returns -1
// 返回此字串中字串str的最後一次出現的索引位置,從索引位置向後搜尋。如果from是-1(預設值),搜尋從最後乙個字元開始;如果from是-2,則在倒數第二個字元處,依此類推。如果沒有找到str,則返回-1。第二個引數可以設定大小寫敏感
qstring x = "crazy azimuths";7、qstring qstring::right(int n) const // 返回包含該字串的最右n個字元的子字串。qstring y = "az";
x.lastindexof(y); // returns 6
x.lastindexof(y, 6); // returns 6
x.lastindexof(y, 5); // returns 2
x.lastindexof(y, 1); // returns -1
8、qstring qstring::left(int n) const // 返回包含該字串的最左n個字元的子字串。
qstring y = x.left(4); // y == "pine"
9、qstring qstring::mid(int position, int n = -1) const // 返回乙個包含該字串的n個字元的字串,從指定的位置索引開始。
qstring y = x.mid(5, 4); // y == "pine"
python中常用字串
轉義字元 因為一些特殊字元是python中的關鍵字或一些特殊的概念如換行。所以以特殊字元 開頭。構造轉義字元。n 換行 t 製表符 單引號 雙引號 反斜槓 for i in abc print i a b c hello 4 0 了解 字串 count 子字串 搜尋子串出現次數 xyaxyaxy c...
Python中常用字串 函式
在 python 有各種各樣的string操作函式。在歷史上string類在 python 中經歷了一段輪迴的歷史。在最開始的時候,python 有乙個專門的string的module,要使用string的方法要先import,但後來由於眾多的 python 使用者的建議,從 python 2.0開...
ACM中常用字串函式
1.字串替換 語法 replace char str,char key,char swap 引數 str 在此源字串進行替換操作 key 被替換的字串,不能為空串 swap 替換的字串,可以為空串,為空串表示在源字元中刪除key 返回值 null 注意 預設str長度小於1000,如否,重新設定設定...