解析分隔的字符串 [英] Parse delimited string
本文介绍了解析分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何获得:
connect
100
username
example
:
ngg://connect>100/username>example/
推荐答案
为了多样性,添加 strtok
的答案:
Adding an answer with strtok
for the sake of diversity:
char str[] = "ngg://connect>100/username>example/";
char *s = strtok(str, ">/");
std::vector<std::string> tokens;
while (s = strtok(NULL, ">/"))
tokens.push_back(std::string(s));
这会将字符串 str
所需的令牌(舍弃第一个 ngg:
,如问题所示)。
这里是此代码的工作示例。
This will split the string str
into the desired tokens (discarding the first ngg:
, like in the question).
Here's a working example of this code.
这篇关于解析分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文