Solved

parse a string until a space

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

932 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

15 Experts available now in Live!

Get 1:1 Help Now