나는 부스트 문자열 라이브러리를 가지고 놀고 있으며 분할 방법의 단순함을 발견했습니다. 좋은 간결 것부스트 분할로 escaped_list_separator 사용
string delimiters = ",";
string str = "string, with, comma, delimited, tokens, \"and delimiters, inside a quote\"";
// If we didn't care about delimiter characters within a quoted section we could us
vector<string> tokens;
boost::split(tokens, str, boost::is_any_of(delimiters));
// gives the wrong result: tokens = {"string", " with", " comma", " delimited", " tokens", "\"and delimiters", " inside a quote\""}
... 그러나 그것은 따옴표와 함께 작동하지 않는 것 대신 나는 다음과 같은
string delimiters = ",";
string str = "string, with, comma, delimited, tokens, \"and delimiters, inside a quote\"";
vector<string> tokens;
escaped_list_separator<char> separator("\\",delimiters, "\"");
typedef tokenizer<escaped_list_separator<char> > Tokeniser;
Tokeniser t(str, separator);
for (Tokeniser::iterator it = t.begin(); it != t.end(); ++it)
tokens.push_back(*it);
// gives the correct result: tokens = {"string", " with", " comma", " delimited", " tokens", "\"and delimiters, inside a quote\""}
내 질문은 분할 할 수있다
또는 다른처럼 뭔가를해야 구분 기호를 인용 할 때 표준 알고리즘을 사용합니까? Purpledog 덕분에 나는 원하는 결과를 성취하기 위해 비추천하지 않는 방법을 이미 가지고있다. 나는 그것을 꽤 복잡하다고 생각한다. 그리고 그것을 더 단순하고 우아한 해결책으로 대체 할 수 없다면, 일반적으로 그것을 사용하지 않고 일반적으로 사용하지 않을 것이다. 또 다른 방법.
편집 : 결과를 표시하고 질문을 명확히하기위한 코드가 업데이트되었습니다.
출력 결과를 함께 표시하면 제공 한 예가 향상됩니다. 코드가 무엇을하는지이 페이지를 찾은 모든 사람에게 풍부하게 알려주는 것입니다. –