loadrunner中切割strtok字符串
http://blog.sina.com.cn/s/blog_7ee076050102vamg.html
http://www.cnblogs.com/lixiaohui-ambition/archive/2012/07/18/2598042.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | int in=0; int j; char buffer[100]= "Fred male 25,John male 62,Anna female 16" ; //char buffer[100]="Fred male 25"; char *p[20]; char *buf = buffer; while ((p[in]=( char *) strtok (buf, "," ))!=NULL) { buf=p[in]; while ((p[in]=( char *) strtok (buf, " " ))!=NULL) { in++; buf=NULL; } buf=NULL; } lr_output_message( "总共分割成:%d个字符串" , in); for (j=0; j<in; j++) { lr_output_message( ">%s<" ,p[j]); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h> #include <string.h> int main( int argc, char **argv) { char buf1[]="aaa, ,a,,,,bbb-c, , ,ee|abc"; //必须为[],即字符串为有名字符串,而非匿名字符串 char * token = strtok ( buf1, ",-| "); while ( token != NULL ) { printf ( "%s" , token ); token = strtok ( NULL, ",-|" ); } printf ( "\n" ); return 0; } OUT 值: aaa abbbc eeabc |
作者:Agoly 出处:https://www.cnblogs.com/qmfsun/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步