从字符串中提取数字
2009-11-17 16:10
155 查看
下面程序将字符串中的连续数字提取出来,并存放到一维数组中。比如说一个字符串:"a284twx234 je3432",把“284“,“234”,“3432”这3个连续数字提取出来,分别存放到a[0],a[1].a[2]中。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
//实现了把一个字符串中的第一次出现的有效数字
//提取出来比如:abge_+*123.456dfsdf
//程序运行的结果应该是:123.456
#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXLEN 50 //定义字符数组的上届
using namespace std;
int main()
//将string类对象中的数字字符提取出来
int CFileIndexDialog::string2int(CString str)
int length;
int i;
TCHAR temp2[15];
lstrcpy(temp2,str); //copies a string to a buffer
TCHAR temp[4];
int count;
count=0;
length=strlen(temp2); //length保存了字符数组temp2的长度
for(i=0;i<length;i++)
if ((temp2[i]<='9')&&(temp2[i]>='0'))
temp[count]=temp2[i];
count++;
}
}
return (::atoi(temp));
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
//实现了把一个字符串中的第一次出现的有效数字
//提取出来比如:abge_+*123.456dfsdf
//程序运行的结果应该是:123.456
#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXLEN 50 //定义字符数组的上届
using namespace std;
int main()
//将string类对象中的数字字符提取出来
int CFileIndexDialog::string2int(CString str)
int length;
int i;
TCHAR temp2[15];
lstrcpy(temp2,str); //copies a string to a buffer
TCHAR temp[4];
int count;
count=0;
length=strlen(temp2); //length保存了字符数组temp2的长度
for(i=0;i<length;i++)
if ((temp2[i]<='9')&&(temp2[i]>='0'))
temp[count]=temp2[i];
count++;
}
}
return (::atoi(temp));
}
相关文章推荐
- java如何提取字符串中不连续数字进行操作
- 提取字符串中的数字并分别保存
- Js 字符串中提取数字
- 计算指针指向的字符串的长度并提取计算字符串中数字的大小
- 大的字符串的中数据转化为数字,字符数值的提取转化,atoi();
- 6 MySQL UDF提取字符串中的字符(中文、英文、数字)
- oracle利用正则表达式提取字符串中的数字
- Oracle中如何判断字符串是否全为数字,以及从任意字符串中提取数字
- java提取字符串中的数字串
- 在sqlserver中如何从字符串中提取数字,英文,中文,过滤重复字符
- 在字符串中提取数字
- JS字符串中提取数字
- 输入一个不定长度的数字字符串,将其中的数字提取出来并保存在数组中。
- Java通过正则表达式提取数字串或者字符串
- js实现在字符串中提取数字 和字母
- java:使用正则提取字符串中的数字(例如提取短信中的验证码)
- 使用Java正则表达式提取字符串中的数字一例
- js实现在字符串中提取数字
- 字符串提取数字
- 用vlookup函数提取字符串中的数字