Solved

parse a string until a space

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

827 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