how to Split a String ? [modified]
-
Helo, If i have a string" 21/jack", how can i let the program to distinguish numeric as age, and String as Name? : for example , from name = jack , age = 21, how can do this ? if possible plz provide more usage of how to split String . thx! Thanks !
modified on Monday, September 28, 2009 8:52 AM
-
Helo, If i have a string" 21/jack", how can i let the program to distinguish numeric as age, and String as Name? : for example , from name = jack , age = 21, how can do this ? if possible plz provide more usage of how to split String . thx! Thanks !
modified on Monday, September 28, 2009 8:52 AM
Since your request looks far from clear, could you please provide an input example (and the expected output)? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Helo, If i have a string" 21/jack", how can i let the program to distinguish numeric as age, and String as Name? : for example , from name = jack , age = 21, how can do this ? if possible plz provide more usage of how to split String . thx! Thanks !
modified on Monday, September 28, 2009 8:52 AM
You use CString::Tokenize[^] to split the string. After you have split the string, convert each one into what you expect them to be (i.e. first one is the age, second is the name, ... ) M.
This signature was proudly tested on animals.
-
Helo, If i have a string" 21/jack", how can i let the program to distinguish numeric as age, and String as Name? : for example , from name = jack , age = 21, how can do this ? if possible plz provide more usage of how to split String . thx! Thanks !
modified on Monday, September 28, 2009 8:52 AM
You may use
CString::Tokenize
[^] (or _tcstok [^] if you're not usingMFC
) to split the string and then, for instance,_tcstol
[^] to discover the actual type of the obtained strings. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]