C++ 中常用的 一些字符串处理

来源:互联网 发布:java游戏制作的书 编辑:程序博客网 时间:2024/06/08 03:26

A: 去掉字符串中的空格

string tempString = text;int begin = 0;begin = tempString.find(" ",begin);  //查找空格在str中第一次出现的位置bool needset = false;while(begin != -1)  //表示字符串中存在空格{needset = true;tempString.replace(begin, 1, "");  // 用空串替换str中从begin开始的1个字符begin = tempString.find(" ",begin);  //查找空格在替换后的str中第一次出现的位置}if (needset){editBox->setText(tempString.c_str());}

0 0