String problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
chinanzio
Posts: 25
Joined: Wed Apr 11, 2007 10:56 am

String problem

Post 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 ?


:oops: my english !!!
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post 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());
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post 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()!
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, you can also reinvent the wheel !!! :lol:

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);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
chinanzio
Posts: 25
Joined: Wed Apr 11, 2007 10:56 am

Post 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 ...
chinanzio
Posts: 25
Joined: Wed Apr 11, 2007 10:56 am

Post by chinanzio »

Thanks dardo too.
chinanzio
Posts: 25
Joined: Wed Apr 11, 2007 10:56 am

Post by chinanzio »

Acki too.
Post Reply