Link to home
Start Free TrialLog in
Avatar of chaoticdemon
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!!!
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chaoticdemon
chaoticdemon

ASKER

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?
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.
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??
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.
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
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......
Nevermind.... I've solved my problem... hehe