Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

parse a string until a space

Posted on 2006-07-03
5
Medium Priority
?
202 Views
Last Modified: 2010-04-01
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
Comment
Question by:rspiege1
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:e_tadeu
ID: 17032572
strint temp2 = temp.substr(0, temp.find_first_of(' '));
0
 
LVL 4

Accepted Solution

by:
e_tadeu earned 300 total points
ID: 17032581
Sorry:

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

=)

0
 

Author Comment

by:rspiege1
ID: 17032596
thanks for the quick response, worked perfectly.
0
 
LVL 4

Expert Comment

by:e_tadeu
ID: 17032979
Do you check connect() return value for SOCKET_ERROR?
0
 

Author Comment

by:rspiege1
ID: 17033615
i'm not quite sure whaty ou mean by the question.  can you elaborate.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question