Computing.Net > Forums > Programming > String split for C++?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

String split for C++?

Reply to Message Icon

Name: Leo the 28C (by Sulfurik)
Date: October 11, 2005 at 17:05:47 Pacific
OS: Windows XP Home SP2
CPU/Ram: 2.8 GHz/448 MB
Comment:

Hello everyone! :-D
OK, I've came across many functions for this, but none works! I need one that works like this:

StringSplit(string str, string delim, vector<string> results)

Either with strings or char arrays, doesn't matter... anyone know? Thanks! ;-)

PS: I need it to work under GCC with no MFC or VC++ please! ;-)

http://www.xthost.info/sulfurik/
http://tsfc.ath.cx
ftp://tsfc.ath.cx
hotline://tsfc.ath.cx

Ruffle Mayo says ROFLMAO! :D



Sponsored Link
Ads by Google

Response Number 1
Name: Gargamel
Date: October 12, 2005 at 17:41:29 Pacific
Reply:

Hi.

What is it suppose to do exactly?


0

Response Number 2
Name: Leo the 28C (by Sulfurik)
Date: October 14, 2005 at 08:15:15 Pacific
Reply:

Well... something like making "hello world" into an array of "hello" and "world"... Do you know? Thanks! ;-)

http://www.xthost.info/sulfurik/
http://tsfc.ath.cx
ftp://tsfc.ath.cx
hotline://tsfc.ath.cx

Ruffle Mayo says ROFLMAO! :D


0

Response Number 3
Name: Gargamel
Date: October 15, 2005 at 19:46:55 Pacific
Reply:

If I understand what you mean correctly, something like that should work:

StringSplit(string str, string delim, vector<string> results)
{
int cutAt;
while( (cutAt = str.find_first_of(delim)) != str.npos )
{
if(cutAt > 0)
{
results.push_back(str.substr(0,cutAt));
}
str = str.substr(cutAt+1);
}
if(str.length() > 0)
{
results.push_back(str);
}
}

This one splits the string str by any char appears in delim, not including this char. For instance, the call SplitString( "abcdefghabcd", "ade", v);
will put in v the strings "bc" "fgh" "bc".



0

Response Number 4
Name: Leo the 28C (by Sulfurik)
Date: October 20, 2005 at 09:31:59 Pacific
Reply:

Hmm... I found something else already, but your function looks more efficient... I'll try it and then I'll tell you if it worked, much thanks! ;-)

http://www.xthost.info/sulfurik/
http://tsfc.ath.cx
ftp://tsfc.ath.cx
hotline://tsfc.ath.cx

Ruffle Mayo says ROFLMAO! :D


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


C++ int statement help Get currently logged on u...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: String split for C++?

How to use string array in C++? www.computing.net/answers/programming/how-to-use-string-array-in-c/9478.html

Good IDE for C/C++ programming www.computing.net/answers/programming/good-ide-for-cc-programming/5423.html

Where can I find free compiler for C? www.computing.net/answers/programming/where-can-i-find-free-compiler-for-c/146.html