ofSplitString throws error

result=ofSplitString(“of rocks”, “of”);

error: no match for ‘operator=’ in ‘result = ofSplitString(const std::string&, const std::string&)(((const std::string&)(& std::basic_string<char, std::char_traits, std::allocator >(((const char*)“of”), ((const std::allocator&)((const std::allocator*)(& std::allocator())))))))’

??

m

what is “result” ?

ofSplitString will return a vector of strings, your error is that it doesn’t know how use the = sign with what you are asking it to set ofSplitString results equal too. I guess result is a string but should be a vector of strings…

for example (off the top of my head):

  
vector < string > myResults = ofSplitString("123, 324, abc, qrx", ",");  
for (int i = 0; i < myResults.size(); i++){  
  cout << myResults[i] << endl;  
}  

does that help?

take care,
zach

hi

what I’m looking to do is

take a user input string and clean up double spaces

  
userText = keyboard->getText();  

above is working fine

  
string cleanText;  
  
cleanText=ofSplitString(userText, " ");  

but whatever I do with ofSplitString throws an error

Mark

sorted

many thanks

Mark

  
  
userText = keyboard->getText();  
  
if (userText.length() > 0) {  
		  
vector < string > myResults = ofSplitString(userText, " ");  
		  
cleanText = myResults[0] + " " + myResults[1];  
  
}