64,685
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int GetNum(char *pszDest, const char *pszSource)
{
int c;
c = 0;
while(*pszSource)
{
if(*pszSource >= '0' && *pszSource <= '9')
{
if(pszDest) pszDest[c] = *pszSource;
c++;
}
pszSource++;
}
return c;
}
int main(void)
{
char *str = "+86 123-4567890#";
char *pDest;
int c;
c = GetNum(NULL, str);
if(!c) return 1;
pDest = (char*)malloc(sizeof(char) * (c + 1));
GetNum(pDest, str);
printf("%s\n", pDest);
free(pDest);
return 0;
}
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
#include <iostream>
using namespace std;
int main()
{
string snum="+86 20-1234567#";
snum.erase(remove_if(snum.begin(), snum.end(), not1( ptr_fun(isdigit))), snum.end());
cout<<snum<<endl;
return 0;
}
char c[20]="+86 20-1234567#";
int j=0;
for(int i=0; i<strlen(c); ++i)
{
if(c[i]=='+'||c[i]=='-'||c[i]=='#')
continue;
c[j++]=c[i];
}
c[j]=0;
cout<<c<<endl;
#include<string>
#include<algorithm>
using namespace std;
bool is(char c)
{
static const string str="+-# ";
return str.find(c)!=string::npos;
}
void main()
{
string snum="+86 20-1234567#";
erase(remove_if(snum.begin(), snum.end(), is), snum.end());
}
#include<string>
#include<algorithm>
using namespace std;
bool is(char c)
{
static const string str="+-# ";
return str.find(c)!=string::npos;
}
void main()
{
string snum="+86 20-1234567#";
erase(remove_if(snum.begin(), snum.end(), is), snum.end());
}