2014-03-05 2 views
-1
size_t foundBegin = mystring.find("["); 

if (foundBegin!=std::string::npos) 
{ 
    size_t foundEnd = mystring.find("]"); 
    if (foundEnd != std::string::npos) 
    { 
// todo 

    } 


} 

이것은 내가 지금까지 가지고있는 것입니다. 마커 사이의 문자열에서 공백 제거 C++

는 내가 정확히 어떻게에만 토큰 [] 토큰 사이의 제거로 변경하는 mystring.erase(remove_if(mystring.begin(), mystring.end(), isspace), mystring.end());

메신저 확실하지 뭔가를 시도했다. 어떤 도움이라도 대단히 감사합니다 !!!

+0

체크 아웃 [string.substr() (http://www.cplusplus.com/reference/string/ : 그것은 세퍼레이터로서 스페이스를 사용하여 단어 입력 단어 소요 문자열/substr /). – TypeIA

+0

@dvnrrs,'std :: string :: substr'은 새로운 문자열을 생성합니다. 'std :: string :: erase'와'std :: string :: find_first_of'를 조합하면 그의 코드는 트릭을 할 것입니다 – Paranaix

+0

당신은 이미 색인을 알고 있습니다. iterator를 만들어서 begin()과 end() 대신에 iterator를 사용하면된다. – chris

답변

-1

단지 std::stringstream 사용

std::stringstream in(your_substring); 
std::stringstream out; 
std::string word; 

while(in >> word) 
    out << word; 

std::string result = out.str(); 
+1

downvote comment please – Manu343726

+0

이 토큰들 사이에는 여러 단어가 1에서 여러개 나 나올 것입니다. –

+0

@ user3112395 좋습니다. 코드에 의해 예상됩니다. 단어 단위로 단어를 가져 와서 출력 스트림으로 밀어 넣는 것입니다. – Manu343726