這裡給大家介紹QString中的兩個函數
1.QString QString::simplified() const
Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.
返回一個字符串,移除從一開始到結尾的空白,每個序列內部的空格替換為一個空格(頭尾的都去掉了)
舉個例子:[cpp]
<SPAN style="FONT-SIZE: 18px"> QString str = " lots\t of\nwhitespace\r\n ";
str = str.simplified();
// str == "lots of whitespace";</SPAN>
QString str = " lots\t of\nwhitespace\r\n ";
str = str.simplified();
// str == "lots of whitespace";'\t', '\n', '\v', '\f', '\r', ' ' 都屬於空白的處理范圍。
2.QString QString::trimmed() const
Returns a string that has whitespace removed from the start and the end.
返回一個字符串,移除從一開始到結尾的空白。也去掉頭尾的空白
舉個例子:
[cpp]
<SPAN style="FONT-SIZE: 18px"> QString str = " lots\t of\nwhitespace\r\n ";
str = str.trimmed();
// str == "lots\t of\nwhitespace"</SPAN>
QString str = " lots\t of\nwhitespace\r\n ";
str = str.trimmed();
// str == "lots\t of\nwhitespace"