我有以下字符串名爲標題:"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(「\」「,// ...);' –