Qt中去除字串中的空格等操作

2021-10-24 16:40:20 字數 729 閱讀 1683

參考部落格:

以下內容是摘抄這篇大神部落格:

使用正規表示式:

qsring.remove(qregexp("^ +\\s*"));

例項

qstring str = "   aa   ";//字串aa前後各三個空格

str.remove(qregexp("^ +\\s*"));

//執行結果: str="aa ";

使用正規表示式:

qsring.remove(qregexp("\\s* +$"));

例項

qstring str = "   aa   ";//字串aa前後各三個空格

str.remove(qregexp("\\s* +$"));

//執行結果: str=" aa";

(1)qstring qstring::simplified() const

返回乙個字串,移除從一開始到結尾的空白,每個序列內部的空格替換為乙個空格(頭尾的都去掉了)

例項

qstring str = "  aaa\t 44\ngood\r\n ";

str = str.simplified();

//結果: str == "aaa 44 good";

報表中去除字元中的空格

substitute text,old text,new text,instance num 用new text替換文字串中的old text。text 需要被替換字元的文字,或含有文字的單元格引用。old text 需要被替換的部分文字。new text 用於替換old text的文字。insta...

python中去除字串中空格,換行問題

先來說說空格問題吧!如果字串之間都是標準空格那就很好辦了。一句話搞定 str str.replace 但是往往有一些情況是,空格不定長,這樣上述辦法就不好處理了。舉個例子 def main str str.replace print str if name main main 執行結果 很明顯不是我...

去除字串中的空格

使用js去除字串內所帶有空格,有以下三種方法 1 replace正則匹配方法 去除字串內所有的空格 str str.replace s g,去除字串內兩頭的空格 str str.replace s s g,去除字串內左側的空格 str str.replace s 去除字串內右側的空格 str str...