Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

parse a string until a space

Posted on 2006-07-03
5
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 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 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.

705 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