converting numerical values to irrlicht strings

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
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

converting numerical values to irrlicht strings

Post by rogerdv »

How can i convert any numerical value to an irrlicht useable string and maybe concatenate it to another string?
ru guo ni yao ai, ni jiang bu hui shi qu
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

hi

string manipulation is kind of strange if you're comming from basic or java.

check out sprintf and swprintf documentation for char strings and wchar strings....

cheers
tom
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

Yes, i was using something like that, but I got weird results and crashes when try to concatenate strings. i was wondering if irrlicht strings implement some kind of conversion for this.
ru guo ni yao ai, ni jiang bu hui shi qu
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

not that i know.

where you must take care is that you can only concatenate wchar strings with wchar strings and char strings with char strings. otherwise you'll get alot of strange symbols printed out.

this should work:

wchar_t myWString=L"Hi";
float myFloat=6.23f;
wchar_t buf[255];
swprintf(buf,"%f", myFloat); // buf == L"6.23"

swprintf(buf,"%f %s",myFloat,myWString);// buf == L"6.23 Hi"

swprintf(buf,"%f %s",3.14,L"Hello"); // buf == L"3.14 Hello"


cheers
tom
R00mpel
Posts: 41
Joined: Sun Nov 09, 2003 10:12 am
Location: Russia, Nizhny Novgorod

Post by R00mpel »

To convert numerical values into strings, you can also use _itoa, _itow, _ecvt, _fcvt and some other functions. See documentation for further information... :roll:
The only thing to fear is running out of beer!
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

Gorgon Zola wrote:not that i know.

where you must take care is that you can only concatenate wchar strings with wchar strings and char strings with char strings. otherwise you'll get alot of strange symbols printed out.

this should work:

wchar_t myWString=L"Hi";
float myFloat=6.23f;
wchar_t buf[255];
swprintf(buf,"%f", myFloat); // buf == L"6.23"

swprintf(buf,"%f %s",myFloat,myWString);// buf == L"6.23 Hi"

swprintf(buf,"%f %s",3.14,L"Hello"); // buf == L"3.14 Hello"
Well, doesnt works. After some trial and error and man, got this:
wchar_t buf[255];
swprintf(buf, 30,L"%s %i", L"Strength ",20); // Strength
statsn->setText(buf);

But this only displays "S 20" instead of "Strength 20"
ru guo ni yao ai, ni jiang bu hui shi qu
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

Yes, right,
I thought I might be missing something in that swprintf function call :?

anyway this works in my app:

swprintf(tmp, 1024, L"%s (fps:%d, primitives:%d)",L"TestApp", fps, primitives);

I don't really see why your code doesn't work seems ok to me.
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

It works!
Thanks a lot.
ru guo ni yao ai, ni jiang bu hui shi qu
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

R00mpel wrote:To convert numerical values into strings, you can also use _itoa, _itow, _ecvt, _fcvt and some other functions. See documentation for further information... :roll:
Most of them are not statndard C / C++ functions and might not be included in all implamentations. And AFAIR they are only wrappers for sprintf() or similar function.
Tomasz Nowakowski
Openoko - www.openoko.pl
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Post by schick »

you might want to have a look at boost. http://www.boost.org there are some lexical cast libraries.
Please send me an e-mail instead of a private message.
Post Reply