有没有办法拆就用C多个字符的字符串? [英] Is there a way to split a string on multiple characters in C?
本文介绍了有没有办法拆就用C多个字符的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有用C的方式来分割字符串,其中分隔符是长度超过一个字符(使用 strtok的
或任何其他方式)?我正在寻找这样的事情:
Is there a way in C to split a string (using strtok
or any other way) where the delimiter is more than one character in length? I'm looking for something like this:
char a[14] = "Hello,World!";
char *b[2];
b[0] = strtok(a, ", ");
b[1] = strtok(NULL, ", ");
我想这是因为逗号和W之间没有空格不能分割字符串有没有办法做到这一点?
I want this to not split the string because there is no space between the comma and the W. Is there a way to do that?
推荐答案
您可以只重复调用 SUBSTR
找到你的边界线和分割沿结果的出现。当你发现了一个结果,由子串的长度推进指针并重新搜索。
You could just repeatedly call substr
to find occurrences of your boundary string and split along the results. After you found a result, advance the pointer by the length of the substring and search again.
这篇关于有没有办法拆就用C多个字符的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文