c语言实现字符串分割
来源:互联网 发布:门店数据分析 编辑:程序博客网 时间:2024/05/21 22:33
用到c函数库的strtok()
先上个例子,显示效果
example:
char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); }
The above code will display the following output:
result is "now " result is " is the time for all " result is " good men to come to the " result is " aid of their country"
说明:strtok(char s[], const char *delim)用来将字符串分割成一个个片段。参数s指向欲分割的字符串,参数delim则为分割字符串中包含的所有字符。当strtok()在参数s的字符串中发现参数delim中包涵的分割字符时,则会将该字符改为\0 字符。在第一次调用时,strtok()必需给予参数s字符串,往后的调用则将参数s设置成NULL。每次调用成功则返回指向被分割出片段的指针。
strtok() 函数里面有个static变量str 记录了第一次调用strtok()函数输入参数的余串,所以第一次调用时strtok()必需给予参数s字符串,往后的调用则将参数s设置成NULL,当参数str为NULL时函数对余串进行处理。
原文链接:http://www.cnblogs.com/linxr/archive/2011/12/28/2304350.html
- c语言实现字符串分割
- c语言实现字符串分割
- c语言实现字符串的分割
- C语言字符串分割
- C语言分割字符串
- C 语言分割字符串
- C语言利用strtok函数实现字符串自由分割
- c语言实现遍历字符串并分割成数组
- C语言字符串分割函数
- c语言的字符串分割
- C语言的字符串分割
- C语言字符串的分割
- C语言之分割字符串
- C语言 strtok 字符串分割
- C语言字符串的分割
- C语言标准字符串分割
- C++:实现split分割字符串
- C++:实现split分割字符串
- Illegal Instruction 错误初窥
- IOS学习——获取iPhone的IP地址
- 准妈妈需要注意事项,准妈妈应该注意什么?
- spring.net学习网站
- BFS小结(持续更新中)
- c语言实现字符串分割
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第一篇:准备工作
- 百度地图查询视野范围内的建筑物
- 数组al[0,mid-1]和al[mid,num-1]是各自有序的,对数组al[0,num-1]的两个子有序段进行merge,得到al[0,num-1]整体有序
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第二篇:第一个页面
- Android 升级ADT后,NoClassDefFoundError问题解决
- HDU2660:Accepted Necklace(DFS)
- Mutex::AutoLock介绍
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第三篇:ASP.NET MVC全局观