分割字符串(转)
来源:互联网 发布:推出mac的应用程序 编辑:程序博客网 时间:2024/05/21 09:40
C语言分割字符串函数strtok
在编程过程中,有时需要对字符串进行分割.而有效使用这些字符串分隔函数将会给我们带来很多的便利.
下面我将在MSDN中学到的strtok函数做如下翻译.
strtok :在一个字符串查找下一个符号
char *strtok( char *strToken, const char *strDelimit );
返回值:返回指向在strToken字符串找到的下一个符号的指针,当在字符串找不到符号时,将返回NULL.每
次调用都通过用NULL字符替代在strToken字符串遇到的分隔符来修改strToken字符串.
参数:
strToken:包含符号的字符串
strDelimit:分隔符集合
注:第一次调用strtok函数时,这个函数将忽略间距分隔符并返回指向在strToken字符串找到的第一个符
号的指针,该符号后以NULL字符结尾.通过调用一系列的strtok函数,更多的符号将从strToken字符串中分
离出来.每次调用strtok函数时,都将通过在找到的符号后插入一个NULL字符来修改strToken字符串.为了
读取strToken中的下一个符号,调用strtok函数时strToken参数为NULL,这会引发strtok函数在已修改过
的strToken字符串查找下一个符号.
Example(摘自MSDN)
/* STRTOK.C: In this program, a loop uses strtok
* to print all the tokens (separated by commas
* or blanks) in the string named "string".
*/
#include <string.h>
#include <stdio.h>
char string[] = "A string/tof ,,tokens/nand some more tokens";
char seps[] = " ,/t/n";
char *token;
void main( void )
{
printf( "%s/n/nTokens:/n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
printf( " %s/n", token );
/* Get next token: */
token = strtok( NULL, seps );
}
}
Output
A string of ,,tokens
and some more tokens
Tokens:
A
string
of
tokens
and
some
more
tokens
- 分割字符串(转)
- [转]Split 分割字符串
- 转:批处理分割字符串
- strtok(分割字符串)
- 分割字符串(CString)
- 字符串分割(C++)
- split分割字符串(按两种符号分割)
- SQL分割字符串函数(转)
- 分割中文字符串(续)
- 字符串分割(split 方法)
- strtok函数(分割字符串)
- Matlab---------字符串分割(split)
- Java字符串分割(split)
- Android 字符串分割split()
- 字符串操作(分割:split)
- 分割字符串
- 分割字符串
- 分割字符串
- Android的ListView中给RadioGroup添加setOnCheckChangeListener的问题之一
- 蓝牙CC2541添加source insight 的时候出现多个同名文件
- HDU 4275 Color the Tree 树的Hash 2012年长春网络赛I题
- [BZOJ2190][SDOI2008]仪仗队
- java基础知识回顾(5)
- 分割字符串(转)
- Cable master
- hdu5327 水题
- 读书笔记MoreEffectiveC++(33)
- 朋友赚 v1.2.0 安卓版
- Celery的安装和使用
- c++ 解决ifstream在断点debug下无法读取文件问题
- hdoj 2141 Can you find it?
- jQuery EasyUI 给datagrid绑定右键菜单