字符串分割
2012-05-17 16:23:38 来源:WEB开发网核心提示:#include <iostream>#include <string.h>#include <stdio.h>#include <sys/types.h>using namespace std;/* 122,11232,122342,122,332-332,212
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
using namespace std;
/*
122,11232,122342,122,332-332,2123-332
如何处理上面到数据呢。。。
*/
//typedef unsigned int uint;
const char *TakeOutStringByChar(const char *src,const char ch,char *outbuff,uint len)
{
/*
三种情况
*sincoder\0
*sincoder*
sincoder*
*/
const char *start = src;
uint substrlen = 0;
bool isfind = false;
while(*src)
{
if(*src == ch)
{
isfind = true;
if(substrlen)
{
if(len <= substrlen)
return NULL;
memset(outbuff,0,len);
memcpy(outbuff,start,substrlen);
return src;
}
else
{
start = ++src;
continue;
}
}
++src;
++substrlen;
}
if(isfind && substrlen)
{
if(len <= substrlen)
return NULL;
memset(outbuff,0,len);
memcpy(outbuff,start,substrlen);
return src;
}
return NULL;
}
int main(int a,char **argv)
{
const char *p = argv[1];
char buff[1024];
while((p = TakeOutStringByChar(p,',',buff,1024)))
{
printf("%s\n",buff);
}
return 0;
}
- ››字符串分割
- ››字符串格式化工具
- ››分割窗口后如何限制分割条的移动范围
- ››字符串近似匹配算法
- ››字符串分割的两种方法
- ››字符串类数据列类型(参考)
- ››分割图像的方法
- ››字符串的一些操作
- ››字符串中文的问题
- ››字符串中包含双引号
- ››字符串函数大全
更多精彩
赞助商链接
