extract a substring from CString
-
Hi all, I am new to C++ and I have to say my biggest hurdle is getting my head around what operations I can do with the various var types. It seems everytime I try and do anything with a CString I get an error telling my 'can't convert CString to char *' or various errors all along these lines. Anyway I think I am starting to get there :-) I need to extract a substring from a CString. i.e. CString = "This is a test string" say i need to get the word test out and store it in an word array. I know what position it starts and i know what position it ends, so I of course know how many chars I need. What should I use to get that word from the CString and stick it in say word_array[word_count]??? Any pointers are greatly appreciated, Cheers Dudes, Tryhard Down Under PS - Thanks to all who have replied to my previous posts esp. C.G. Thanks Dude, very helpfull :-) Tryhard :-)
-
Hi all, I am new to C++ and I have to say my biggest hurdle is getting my head around what operations I can do with the various var types. It seems everytime I try and do anything with a CString I get an error telling my 'can't convert CString to char *' or various errors all along these lines. Anyway I think I am starting to get there :-) I need to extract a substring from a CString. i.e. CString = "This is a test string" say i need to get the word test out and store it in an word array. I know what position it starts and i know what position it ends, so I of course know how many chars I need. What should I use to get that word from the CString and stick it in say word_array[word_count]??? Any pointers are greatly appreciated, Cheers Dudes, Tryhard Down Under PS - Thanks to all who have replied to my previous posts esp. C.G. Thanks Dude, very helpfull :-) Tryhard :-)
To get a substring out of a CString you can use left, mid, or right. For example, in the above example you could use CString s = "This is a test string"; CString y = s.Mid(10, 4); As usual, you can use SetBuffer and ReleaseBuffer in order to get the underlying data if you need to. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.