Page 1 of 1
String problem
Posted: Sat Dec 15, 2007 11:32 am
by chinanzio
hello , i've got a problem , i would like to do this :
Code: Select all
char Name[] = "Node01";
IGUIEditBox* EditBox = addEditBox(...);
EditBox->setText(Name);
of course this does not work , the question is , what can i do ?
wchar_t* to char* conversion ? , how is done it ?
my english !!!
Posted: Sat Dec 15, 2007 12:04 pm
by Sylence
you could forget the char[] and use irrlicht's string class instead.
Code: Select all
core::stringw Name = "Node01";
EditBox->setText(Name.c_str());
Posted: Sat Dec 15, 2007 12:20 pm
by Nadro
You can easy convert char* to wchar_t* eg.
Code: Select all
char* Name = "NPC_Name";
int NameSize = strlen(Name);
wchar_t *Name_t = new wchar_t[NameSize+1]; // You have to create new wchar_t with size of Your char*
for (int i=0; i<=NameSize; i++)
{
if (Name[i] == 'ą') Name_t[i] = L'ą'; // for multibyte signs eg. Ą, Ź etc. You have to add multibyte support for Your project
Name_t[i] = Name[i]; // for all standard signs eg. A,B,c,d etc.
}
IGUIEditBox* EditBox = addEditBox(...);
EditBox->setText(Name_t);
delete[] Name_t; You have to free memory!
With this trick You can easy use char* and std::string after convert it to char* by .c_str()!
Posted: Sat Dec 15, 2007 1:23 pm
by Acki
well, you can also reinvent the wheel !!!
If you don't want to use the string class, you can use this functions for converting (also a search on the forum discoveres this):
Code: Select all
// convert from char* to wchar_t*
mbstowcs(wchar_t*, const char*, size_t);
// convert from wchar_t* to char*
wcstombs(char*, const wchar_t*, size_t);
Posted: Sat Dec 15, 2007 1:38 pm
by chinanzio
Sylence wrote:you could forget the char[] and use irrlicht's string class instead.
Code: Select all
core::stringw Name = "Node01";
EditBox->setText(Name.c_str());
Yeah , works , thanks , now i have to change a lot of code , jeje ...
Posted: Sat Dec 15, 2007 1:39 pm
by chinanzio
Thanks dardo too.
Posted: Sat Dec 15, 2007 1:41 pm
by chinanzio
Acki too.