JString to std::string

edited April 2013 in Native
How do I convert the JString to a std::string value?
I tried to use the JString toString() method but it has no overload that will return an std:string.


  • Found a way, nevermind...
    jText = lib.getStateString();
    text = jText.UTF8Representation();
  • Hi.

    toString() is the stringifying interface. So if you call myOperation.toString(), or myRoom.toString() then it will return you the Content of the instance, on which toString() has been called, as a JString in human readable format. Thats mainly useful for debugging purposes. For example you can check, if data, that you expect in a container, actually is in there and actually has the datatype that you expect it to have.
    for reasons of consistency and convenience, JString also implements the ToString interface, although its implementation just returns L"\"" + *this + L"\"", meaning, it does nothing more than adding quotation marks to the returned copy of itself for readability reasons.

    JString is a widestring, that internally holds its data in a wchar_t* just like std::wstring does, so its content has to be converted into a narrow string format like UTF8 or the current locale, when converting it to a 8 bit string. This is done by the subclasses of BaseCharString. Please have a look into the doc inside the client SDK for more info about those classes and also about class JString.
Sign In or Register to comment.