Lets say I have a string "The brown fox jumped over the fence.", how can I Split the string by a given deliminator? For example if I gave " " (space) as a deliminator, it would put each word into an array. Also any String Manipulation reference would be useful.
I found http://www.cplusplus.../string/string/ but it doesn't appear to have what I want in there.
String Manipulation
Page 1 of 15 Replies - 648 Views - Last Post: 19 February 2010 - 04:51 PM
Replies To: String Manipulation
#2
Re: String Manipulation
Posted 19 February 2010 - 11:23 AM
You might try reading this excellent tutorial from Martyn.Rae, and telling us what language you're using.
#4
Re: String Manipulation
Posted 19 February 2010 - 11:29 AM
OK, so go read the tutorial. You might find it helpful.
#6
Re: String Manipulation
Posted 19 February 2010 - 04:51 PM
If you only have one delimiter, then getline from a stringstream might be the simplest - the default delimiter is '\n' (a newline character) - but you can specify a different one.
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
int main()
{
std::vector<std::string> vec;
std::string token, str
= "The quick brown fox jumps over the lazy dog";
std::istringstream buffer(str);
while( std::getline(buffer, token, ' ') )
vec.push_back(token);
}
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|