|
-
January 29th, 2010, 11:34 PM
#16
Re: splitting a string
lol I can get it down to 3 lines inside a function, but no one liner . Perhaps 2
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
January 29th, 2010, 11:51 PM
#17
Re: splitting a string
I should've said "a single line of statement" instead of just saying a single line.
My one liner spans across the screen little too much
So I'm sure your 2 lines is as good as mine, if not better.
-
January 30th, 2010, 12:12 AM
#18
Re: splitting a string
lol here is my code 
Code:
void Tokenize( const string& TokenString, vector< string >& Tokens, char Delimiter = '$' )
{
string Token;
stringstream TokenSplitter( TokenString );
while( getline( TokenSplitter, Token, Delimiter ) ) Tokens.push_back( Token );
}
and this is how you use it
Code:
vector<string> Tokens;
Tokenize( "1 2$3$4\n5$6", Tokens );
I think that is 3 statements enjoy
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
January 30th, 2010, 01:10 AM
#19
Re: splitting a string
 Originally Posted by Joeman
I think that is 3 statements  enjoy
That's great 
Mine can be used if there's no luxury of affording 3 statements 
Code:
void Chunkify(const string& s, vector<string>& v, unsigned int p = 0, char delim = '$')
{
return string::npos != (p = s.find(delim)) ? v.push_back(s.substr(0, p)), Chunkify(s.substr(p + 1), v, p) : v.push_back(s);
}
and can be used with a similar function call as yours
Code:
vector<string> Tokens;
Chunkify( "1 2$3$4\n5$6", Tokens );
But as I said before, I'm sure yours is better
-
January 30th, 2010, 01:53 AM
#20
Re: splitting a string
lol nice one That is some way of doing it
I suppose you can take out that return keyword in your function?
Last edited by Joeman; January 30th, 2010 at 01:56 AM.
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
January 30th, 2010, 02:05 AM
#21
Re: splitting a string
 Originally Posted by Joeman
I think that is 3 statements
Four, depending on your point of view. But you probably should have let farooq124in try it first.
-
January 30th, 2010, 02:17 AM
#22
Re: splitting a string
I am not complaining since farooq124in did try enough and it is only so little of code. It isn't 100 lines of unique code 
You will notice I didn't include headers for a reason
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
January 30th, 2010, 02:24 AM
#23
Re: splitting a string
 Originally Posted by Joeman
You will notice I didn't include headers for a reason
Heheh
-
January 30th, 2010, 06:41 PM
#24
Re: splitting a string
 Originally Posted by Joeman
I suppose you can take out that return keyword in your function?
Haha of course! 98% of the time!
I just left it there to help improve what little purpose there is to indicate that the function is recursive
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|