Languages

Menu
Sites
Language
Convert String to char*

Could someone please tell me how to convert a Tizen String object to a char* pointer?

I tried the GetPointer method on the String object but I get wchar_t* instead of char*.

Thank you for your help.

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

2 Replies
Alex Dem

Hi,
Please try this way:
const wchar_t* pWCharStr =text.GetPointer();
char str[200];
sprintf(str, "%S", pWCharStr );
Alexey.   

 

Gary V

The C++ way:

std::string NarrowString(const std::wstring& str, const char* localeName = "C")
{
    std::string result;
    result.resize(str.size());

    std::locale loc(localeName);

    std::use_facet<std::ctype<wchar_t> >(loc).narrow(
        str.c_str(), str.c_str() + str.size(), '?',  &*result.begin());

    return result;
}

Hope this helps,

Gary