【发布时间】:2015-05-18 11:42:20
【问题描述】:
如何提取两个指定字符串之间的字符串?
例如:
<title>Extract this</title>。有没有使用strtok() 或更简单的方法来获取它?
编辑:指定的两个字符串是<title> 和</title>,提取的字符串是Extract this。
【问题讨论】:
-
strstr()更好。 -
只是为了呼应@iharob 先生所说的话,请参阅here。
-
我认为 OP 想要类似于
<title>[extract me]<title>的东西作为 regexp。 -
sscanf(string, "<title>%[^<]</title>", extracted_string);或sscanf(string, "%*[^>]>%[^<]<%*[^>]>" , extracted_string);将完成这项工作。还建议检查返回值。第一个sscanf中的</title>和第二个中的<%*[^>]>不是必需的。