How to get substring from CCString?

I have searched both google and forums and cannot figure out how get a substring from CCString or to compare if CCString contains a substring.

Using cocos2d-x v2.0

Thanks

Simply get string from it.

eg.

CCString* pString = CCString::create("Hello world");
std::string hello = pString->m_sString.substr(0,5);

http://www.cplusplus.com/reference/string/string/substr/

also could use pString.getCString(); which return const char*

take a look in CCString.h
/** get the C string /
const char
getCString() const;

not sure please try. :smiley:

Thanks for responses …

@gelldur - What is m_sString in the second line?

It attribute std::string in CCString which save string you assign to CCString

Go to class and checkout.

m_sString is a std::string

http://www.cocos2d-x.org/reference/native-cpp/V2.2.2/dd/d36/classcocos2d_1_1_c_c_string.html

okay thanks birdcpe25

One last question…

How do I convert the std::string hello back to CCString pString?

Thanks

:slight_smile: create the new CCString one for pString
or assign m_sString directly
std::string m_sString; << this one is public then you could do whatever you want with this thing