chaoticdemon
asked on
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!!!
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!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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??
ASKER
Can u pls illustrate with codes?
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.
ASKER
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
ASKER
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......
ASKER
Nevermind.... I've solved my problem... hehe
ASKER