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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
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
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
All Courses

From novice to tech pro — start learning today.