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

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());
		}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章