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删除。