假设我们有这样的 URL:
dvb://1.3f3.255c.15
我的问题是如何用以下方式解析这个地址:
val1 = 1
val2 = 3f3
val3 = 255c
val4 = 15
第一个想法是使用标准 C 库中的 strchr()
,但以前可能用过。我想让它尽可能简单。当我成功时,我会提出我的解决方案。
最好的问候
最佳答案
你可以使用 strtok
char dvb_url[] = "dvb://1.3f3.255c.15";
//Begin stripping the scheme (dvb:/)
char *tokenized = strtok(dvb_url, "/");
//Finish stripping scheme
tokenized = strtok(NULL, "/.");
while(tokenized != NULL)
{
//Store in variable here
printf("%s\n", tokenized);
tokenized = strtok(NULL, ".");
}
关于c - 将 dvb url 地址拆分为单独的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7123115/