我在下面的表格数据:找出特定字符串在C/C++
http://website.org/resource/id_xa5x8p_1sz_1s8rhrc
http://website.org/resource/abc
http://website.org/resource/id_xa5x8p_1sz_1s8rfcc
http://website.org/resource/def
http://website.org/resource/ghi
http://website.org/resource/id_xa5x8p_1sz_1s8ryurc
http://website.org/resource/id_xa5x8p_1sz_1s8rhrcwjf
http://anyother/anthingelse/id_xa5x8p_1sz_1s8rhrc
file://anyotherInfo/anthingelse1/id_xa5x8p_1sz_1s8rhrc
file://anyotherInfo/anthingelse1/def/id_xa5x8p_1sz_1s8rhrc
file://id_anyotherInfo/anthingelse1/def/id_xa5x8p_1sz_1s8rhrc
file://anyotherInfo/id_anthingelse1/def/id_xa5x8p_1sz_1s8rhrc
file://anyotherInfo/id_anthingelse1/def/ghi
我的预期成果是:
http://website.org/resource/id_xa5x8p_1sz_1s8rhrc
http://website.org/resource/id_xa5x8p_1sz_1s8rfcc
http://website.org/resource/id_xa5x8p_1sz_1s8ryurc
http://website.org/resource/id_xa5x8p_1sz_1s8rhrcwjf
http://anyother/anthingelse/id_xa5x8p_1sz_1s8rhrc
file://anyotherInfo/anthingelse1/id_xa5x8p_1sz_1s8rhrc
file://anyotherInfo/anthingelse1/def/id_xa5x8p_1sz_1s8rhrc
file://id_anyotherInfo/anthingelse1/def/id_xa5x8p_1sz_1s8rhrc
file://anyotherInfo/id_anthingelse1/def/id_xa5x8p_1sz_1s8rhrc
现在我想找出所有的URL具有字符比如最后一个斜杠后面的“id_”。我所知道的和我已经实现的一种方法是从一开始就逐字符地解析这个字符串,并将这个字符串存储到一个数组中,直到我得到一个空格。现在我选择最后一个数组,并在开始时查找它是否具有id_。
但我的问题是在C++中的数组大小被分配为先验,因此当有许多斜杠时这种方法是不可行的。有没有其他方法可以找到答案。
['的std :: string :: find'(http://en.cppreference.com/w/cpp/string/basic_string/find)是你的朋友。 – 2014-10-31 15:14:44
[''](http://www.cplusplus.com/reference/regex/) –
CoryKramer
2014-10-31 15:15:12
C!= C++。通常,只标记您正在使用/编译的语言。 – crashmstr 2014-10-31 15:16:39