Page 1 of 1

converting numerical values to irrlicht strings

Posted: Sat Apr 24, 2004 5:26 pm
by rogerdv
How can i convert any numerical value to an irrlicht useable string and maybe concatenate it to another string?

Posted: Mon Apr 26, 2004 1:06 pm
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

Posted: Mon Apr 26, 2004 1:12 pm
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.

Posted: Mon Apr 26, 2004 1:20 pm
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

Posted: Mon Apr 26, 2004 6:11 pm
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:

Posted: Mon Apr 26, 2004 7:03 pm
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"

Posted: Tue Apr 27, 2004 7:40 am
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.

Posted: Tue Apr 27, 2004 12:16 pm
by rogerdv
It works!
Thanks a lot.

Posted: Tue Apr 27, 2004 12:53 pm
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.

Posted: Tue Apr 27, 2004 3:57 pm
by schick
you might want to have a look at boost. http://www.boost.org there are some lexical cast libraries.