一个关于特定分隔符分割字符串的问题(用strtok并不理想)

bigzhizhi bigzhizhi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
比如一个字符串
char GPS_INFO[]="$GPRMC,112720.000,A,3639.2868,N,11659.8396,E,,,200305,,*12"
用","为分隔标志将里面的指定参数信息提取出来,C语言怎么实现?

希望以如下函数形式实现
char *strSplict(char *str,const char *seps,int pos)
其中str是原字符串,seps为分隔符,pos为指定位置.
比如 info3=strSplict(GPS_INFO,",",3)应为"3639.2868";

我尝试过strtok,但很有意思的是遇到",,,"这样的空段它自作主张的给去掉了(我的意思是就算空茅坑它也必须得给我留着,好让我跟序号一一对上)
...全文

相关推荐

经典的C语言字符分割文档

主要介绍如何分割带有逗号或者其他符号字符串,分割成字符串数组

huohuohong54312

C++ 字符串截取(strtok)

C++字符串截取,例如:"adda,dagf,dfa,df",将','去除,将每部分字符出入一个指定数组

飞尚云霄

C语言切割多层字符串(strtok_r strtok使用方法)

主要介绍了C语言切割多层字符串的方法,说了strtok的弱点,使用strtok_r的方法

weixin_38727928

strtok的缺陷,使用strtok_s函数更新安全度

strtok的缺陷,使用strtok_s函数更新安全度 #include "stdafx.h" #include "Windows.h" #include #include using namespace std; char string1[] = "A string\tof ,,tokens\nand some more tokens"; char string2[] = "Another string\n\tparsed at the same time."; char separators[] = " ,\t\n"; char *token1, *token2, *next_token1, *next_token2; int main(void) { cout << "Tokens:" << endl; // establish a string and get the first token: token1 = strtok_s(string1, separators, &next;_token1); token2 = strtok_s(string2, separators, &next;_token2); // while there are tokens in "string1" or "string2" while ((token1 != NULL)) { // get the next token: if (token1 != NULL) { cout << token1 << endl; token1 = strtok_s(NULL, separators, &next;_token1); OutputDebugString(_T(token1)); } } while ((token2 != NULL)) { // get the next token: if (token2 != NULL) { cout << token2 << endl; token2 = strtok_s(NULL, separators, &next;_token2); OutputDebugString(_T(token2)); } } Sleep(3000); system&#40;"pause"&#41;;

yelenn1115

strtok函数的使用示例

今天小编就为大家分享一篇关于strtok函数的使用示例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

weixin_38681318
评论 12
收藏 已收藏
分享
返回顶部
bigzhizhi
C语言 70,039 成员 243,237 内容