Question on obtaining sub-string from a string

Say I've got the following string:
Example: David Chua Vibro company Lubrication oil
The above string simply means, David chua is working in vibro company selling lubrication oil.
How can I extract these 3 informations out from the string into 3 CString variables namely: name, company and product?
i.e. CString name, company, product;
So the end result that I wanted will be like this:
name = David Chua
company = Vibro company
product = Lubrication oil
Any help on this will be appreciated!!!
chaoticdemonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
You can use CString::Find to find the position of the space and use CString::Left and CString::Right to extract the three items.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chaoticdemonAuthor Commented:
Well, I've tried it before can only get the first and the second sub-string.... pls assume that there are no fix length to all the 3 sub-string.... can u pls show me the code?
0
chensuCommented:
Since you can get the first and second strings, you should be able to get the rest. You use CString::Find to find the position of the first space. Then, use CString::Left and CString::Right to split the string into two parts. Now that you get the first string. Then simply repeat these steps until you get all the strings.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

chaoticdemonAuthor Commented:
But I still got some problems with the name... like it's not always David Chua, it can be David Chua Chin Teng etc... so how can I actually differentiate the name from the rest of the sub-strings??
0
chaoticdemonAuthor Commented:
Can u pls illustrate with codes?
0
chensuCommented:
I don't think there is a way to differentiate the name from the rest of the sub-strings. How can you tell it is a part of name or company? Even people may not be able to do that, not to mention computers.
0
chaoticdemonAuthor Commented:
You see..... now I've inserted a single character code to the end of each variable to help me identify where it's a name or company..... but I'm having problem  extracting the 3 sub-strings though
0
chaoticdemonAuthor Commented:
Maybe I just need to code to extract the sub-strings or rather to illustrate the usage of CString Find(), Left() etc.....Any help will be very much appreciated......
0
chaoticdemonAuthor Commented:
Nevermind.... I've solved my problem... hehe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.