C++ 中,利用string 類自帶方法,去除兩端空格。
1 //C++ 去字符串兩邊的空格 2 void delete_space(string &s) 3 { 4 if (s.empty()) 5 { 6 return ; 7 } 8 s.erase(0,s.find_first_not_of(" ")); 9 s.erase(s.find_last_not_of(" ") + 1); 10 }
C++ 中,利用string 類自帶方法,去除兩端空格。
1 //C++ 去字符串兩邊的空格 2 void delete_space(string &s) 3 { 4 if (s.empty()) 5 { 6 return ; 7 } 8 s.erase(0,s.find_first_not_of(" ")); 9 s.erase(s.find_last_not_of(" ") + 1); 10 }
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。