Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

ToString conversion problem

Hi there!

I have a little problem with type conversions.
I need to convert a two number nteger (System::Int32 ^xx) retreived from ActiveX control
to a System::String. I'm using Visual Studio 2005 (.NET).Here's the code:

try
{
int xx; /*initialize a new 32bit singed
integer,named "xx" */

xx = (vid->CurrentDomain); /*MsWebDVDLib::MsWebDVD->
CurrentDomain*/
System::String ^s1; /*initialize a new System::String,
named "s1"*/

static s1 = (xx::ToString()); /*trying to convert from System::Int32
to System::String.*/

domaininfo->Text::set (s1); /*Set label text*/
}
catch(...)
{

}

}
[1028 byte] By [DragonArt] at [2007-11-11 7:25:59]
# 1 Re: ToString conversion problem
I still always just use sprintf for this. See if you can use that instead?
jonnin at 2007-11-11 21:02:25 >
# 2 Re: ToString conversion problem
The ToString conversion is a lot easier, faster and Visual C++ .NET natively use it.
Oh, by the way, i resloved the problem. The problem was that I was tried to use the ToString-method directly to a string, the MsWebDVD was confused because of using the System::Int32 ^, NOT just the native [/B]int AND there's a bug, I'll show it here:

[B]int integer1;
integer1 = (MsWebDVD->CurrentAudioStream);
label1->Text = (integer1::ToString()) // Here's the bug. Wen you try to compile this, it just says: "Illegal call of non-static member.". BUT when using System::Int32, everything is okay.
DragonArt at 2007-11-11 21:03:19 >
# 3 Re: ToString conversion problem
Well done.

I don't use the managed extensions - I try not to use non-portable code unless there is no other way to do it -- It all depends on your project needs but over time our stuff has a good shot at being ported. Can you show me the timings you found that show this item to be faster than sprintf'ing directly into the char buffer of the string class? I have always found it to be faster than more OOP style conversions.
jonnin at 2007-11-11 21:04:25 >