0

如何在令牌之后复制部分字符串

我有这个输入

微软公司; 纳斯达克 MSFT 259.94B

如何复制从 NASDAQ 开始到字符串末尾的部分字符串,这里的标记是分号

像这样的东西会起作用吗?

strcpy(tempString, strtok(buffer, ";")+4)
4

1 回答 1

4

Something like your code would work. I don't understand the + 4, though, as far as I'm concerned, it should be + 2. Also, don't use strtok() for finding a character in a string - use strchr() for that, it's more lightweight and it doesn't require the base string to be modifiable.

So,

strcpy(tempString, strchr(buffer, ';') + 2);

or the safer

snprintf(tmp, sizeof tmp, "%s", strchr(buffer, ';') + 2);

is what you are looking for.

于 2013-08-06T16:56:12.837 回答