C++去掉字串中重複空格
#include<string.h>
using namespace std;
void delSpace(char* buf)
{
//int len = strlen(buf);
//int i,j;
//if(i = 0; i < len;i++)
char* fast = buf;
char* temp = buf;
while(*fast!='\0')
{
if(*fast!=' ')
{
*temp=*fast;
temp++;
fast++;
}
else
{
while(*fast == ' ')
fast++;
//cout<<*fast;
*temp=' ';
temp++;
}
}
*temp='\0';
}
int main()
{
char s[100];int i = 0;
cin.getline(s,100);
delSpace(s);
i=0;
while(1)
{
if(s[i]=='\0')
break;
else
cout<<s[i];
i++;
}
return 0;
}
相關推薦
C++去掉字串中重複空格
#include<iostream> #include<string.h> using namespace std; void delSpace(char* buf) {//int len = strlen(buf);//int i,j;//if(i
MATLAB中去掉字串中的空格,num2str引發的問題
MATLAB中去掉字串中的空格(前後以及中間)的函式 去掉前後的空格:strtrim(); eg: >> a = ' Keep Moving ', aLen = length(
c# 去掉DataTable中重複行
DataView dv = new DataView(dtOld); DataTable dtmc = dv.ToTable(true, new string[] { "common_name" });//common_name:所要篩選的欄位
js中去掉字串中的空格
1、 去掉字串前後所有空格:程式碼如下:?1234function Trim(str){ return str.replace(/(^\s*)|(\s*$)/g, ""); } 說明: 如果使用jQuery直接使用$.trim(str)方法即可,str表示要去掉
js去掉字串中所有空格
通過迴圈,去掉所有空格 var s="1223 332 "; while(s.indexOf(" ")!=-1) { s=s.replace(" ","");} alert(s); 去掉字串中的
c++ 去除字串中的空格和標點符號 (remove_if 函式的用法)
C++中提供了自動刪除空格和標點符號的函式,使用如下: #include <ctype.h> #include <algorithm> str_testing.erase(
使用Swift去掉字串中的空格
筆試面試時經常會出這樣的問題:從某個字串中刪除多餘的空格,因為英文是使用空格進行分詞的,而URL中通常會包括非常多的特殊字元,所以這是一種很常用的做法。和OC中一樣,在swift中也可以使用NSCharacterSet類來實現。對於字串刪空格操作,通常有兩種情況
C#去掉字串中的標籤
Regex reg = new Regex(@"(?is)(?<=<P>).*?(?=</P>)", RegexOptions.IgnoreCase); st
C++ 去掉string字串中首尾空格和所有空格
c++去掉首尾空格是參考一篇文章的,但是忘記文章出處了,就略過吧。 去掉首尾空格的程式碼如下: 1 void trim(string &s) 2 { 3 4 if( !s.empty() ) 5 { 6 s.era
去掉字串中的多餘空格
#include <iostream> #include <string> using namespace std; string reverse(string s) { string res = ""; string::size_type start = 0;
java開發實戰1200(I)--------081去掉字串中的所有空格
package DeleteBlank; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListen
Qt程式設計中如何去掉字串中多餘的空格
一,自己建立函式解決 void deBlank(QString &strs) { int len = strs.length(); for (int i=0;i<len;i++) {
輸出的字串中有空格並且無法替換B e a r e r N D c y Z T g 4 N z A t N 2 N h Z C 0 0 Y 2 E 4 L T g x M W E t O D Y
###1.檔案如下: Request url: appv2.qichacha.net/app/v1/extras/getVersion?platform=android&version=11.3.0×tamp=1543816102814&sign=ddc
C語言刪除字串中重複的字元
#include <stdio.h> #include <string.h> #define NR(x) sizeof(x)/sizeof(x[0]) int Del_cha
C++去除字串中多餘的空格
今天寫了個小程式設計,去除字串中多餘的空格,例如"I___am_____a______student."(下劃線表示空格哈,打多個空格顯示的還是一個),最後輸出”I am a student.” 現在把自己的思路貼上,歡迎大家留言指正。 思路就是定義兩個指標
c#輸入一個字串,並把字串的第一個字元變為大寫,如果字串中有空格則把空格的下個字元變為大寫之後輸出
using System; using System.Collections.Generic; using System.Text.RegularExpressions; delegate int MyDelegate();//相當於c函式指標 namespace c
c# String.Join 和 Distinct 方法 去除字串中重複字元
1.在寫程式中經常操作字串,需要去重,以前我的用方式利用List集合和 contains去重複資料程式碼如下: 1 string test="123,123,32,125,68,9565,432,6543,343,32,125,68"; 2 string[] array = test.Spli
python去掉字串中空格的方法
1.strip():把頭和尾的空格去掉 2.lstrip():把左邊的空格去掉 3.rstrip():把右邊的空格去掉 4.replace(‘c1’,’c2’):把字串裡的c1替換成c2。故可以用replace(’ ‘,”)來去掉字串裡的所有空格 5
C語言實現移除字串中的空格,並將空格數列印
某次被問到這一簡單問題,想想以前學C語言的時候是知道的,那會卻怎麼也想不起來,現在回顧。 這裡用兩種方式實現移除: 陣列實現 #include <stdio.h> #include <string.h> /*用陣列實現移
c++ 實現字串中替換字串,也可去掉字串中特定字串
int string_replase(string &s1, const string &s2, const string &s3) { string::size_type pos = 0; string::size_type a = s2.si