Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

parse a string until a space

I just wanted to know the best way to parse the following string.

string temp = "200   SU90";

I would like to end up with everything in the string above before the space.  After that I would like to remove the last character of what is retrieved.  So in the string above I am trying to get "20" as a result.

Just curious the easiest way to do this in c++

thanks
0
rspiege1
Asked:
rspiege1
  • 3
  • 2
1 Solution
 
e_tadeuCommented:
strint temp2 = temp.substr(0, temp.find_first_of(' '));
0
 
e_tadeuCommented:
Sorry:

string temp = "200   SU90";
string temp2 = temp.substr(0, temp.find_first_of(' ') - 1);

=)

0
 
rspiege1Author Commented:
thanks for the quick response, worked perfectly.
0
 
e_tadeuCommented:
Do you check connect() return value for SOCKET_ERROR?
0
 
rspiege1Author Commented:
i'm not quite sure whaty ou mean by the question.  can you elaborate.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now