Click to See Complete Forum and Search --> : [VC++ 2003] toString()-Method of MAC-Address-Class


thegrinch
January 31st, 2007, 05:24 AM
Hi!
I am not so familiar with this managed c++, but I have to work with mac addresses in managed code.
I'm trying to implement the ToString() method of a Wrapper Class for Mac-Addresses. So, I tried the following:


System::String * MACAddress::ToString()
{
//b1,b2,... are just private member int's
return System::String::Format(S"%02x-%02x-%02x-%02x-%02x-%02x", b1,b2,b3,b4,b5,b6);
}

doesn't work, since there is no Format(..) method with 7 parameters.

next try:
System::String * MACAddress::ToString()
{
int b[6];

b[0] = _b1;
b[1] = _b2;
b[2] = _b3;
b[3] = _b4;
b[4] = _b5;
b[5] = _b6;

return System::String::Format(S"%02x-%02x-%02x-%02x-%02x-%02x", b);
}

Now, the problem is that b is not of type Object*[].

I'm sure the solution is easy!

Thanks for your help in advance!

Kind regards!

thegrinch

darwen
January 31st, 2007, 11:14 PM
Microsoft have changed the formatting of strings in .NET.

You should try


int a = 100;
String *theString = String::Format(S"{0}", a);


There are a load of resources on the net about this, like here. ('http://blog.stevex.net/index.php/string-formatting-in-csharp/')

Darwen.