Solved

parse a string until a space

Posted on 2006-07-03
5
193 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 75 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now