我需要这个简单的分割
Item one, Item2, Item no. 3,Item 4
>
Item one
Item2
Item no.3
Item 4
我真的需要正则表达式,还是有任何有效的简短编码方式?
答案 0 :(得分:6)
如下:
char inputStr[] = "Item one, Item2, Item no. 3,Item 4";
char* buffer;
buffer = strtok (inputStr, ",");
while (buffer) {
printf ("%s\n", buffer); // process token
buffer = strtok (NULL, ",");
while (buffer && *buffer == '\040')
buffer++;
}
输出:
Item one
Item2
Item no. 3
Item 4
答案 1 :(得分:0)
您可以单步执行字符串查找,或者0x00并替换任何一个0x00,然后跳过任何空格以查找下一个字符串的开头。正则表达式更容易。