我有以下字符串名为标题:"bla bla hello, just more characters filename="myfile.1.2.doc" more characters"
如何从cpp中给定的字符串中提取特定的字符串?
我需要的文件名,并从该字符串的文件类型,但我的解决办法似乎很凌乱(伪代码):
unsigned int end = header.find("filename=");
unsigned int end2 = header.find(" " ", end + sizeof("filename=") + 1) // how to search for ' " ' ?!
std::string fullFileName = header.substr(end +sizeof("filename=") + 1 ,end2 -1);
//now look for the first "." from the end and split by that .
如何从cpp最后看?
使用“as a”而不是解析令牌:\“ – user4581301
您需要*转义*字符串文本中的任何双引号字符。例如:'header.find(“\”“,// ...);' –