Is there equivalent of sscanf function in .NET?
I need to parse string with network MAC address (For example like
11-22-33-44-55-66) and extract each segment into array of bytes.
Can anyone advise what method/class I can use for that?
I've figured out how to parse IP address: IPAddress.Parse(hostName), but
can't find easy way to parse MAC address.
Thanks
Tomas Restrepo \(MVP\) - 04 May 2005 00:54 GMT
Steve,
> Is there equivalent of sscanf function in .NET?
>
[quoted text clipped - 5 lines]
> I've figured out how to parse IP address: IPAddress.Parse(hostName), but
> can't find easy way to parse MAC address.
How about just:
Byte ParseMac(String* mac) __gc[]
{
Char delim __gc[] = { '-' };
String* macParts __gc[] = mac->Split(delim);
Byte macBytes __gc[] = new Byte __gc[macParts->Length];
for ( int i=0; i < macParts->Length; i++ ) {
macBytes[i] = Convert::ToByte(macParts[i], 16);
}
return macBytes;
}

Signature
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/
Steve - 04 May 2005 14:46 GMT
Thank you
"Tomas Restrepo (MVP)" wrote:
> Steve,
> > Is there equivalent of sscanf function in .NET?
[quoted text clipped - 20 lines]
> return macBytes;
> }
Ioannis Vranos - 04 May 2005 22:05 GMT
> Is there equivalent of sscanf function in .NET?
>
[quoted text clipped - 5 lines]
> I've figured out how to parse IP address: IPAddress.Parse(hostName), but
> can't find easy way to parse MAC address.
For converting a character digit to a number you may use Char::GetNumericValue() static
member function:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemcharmemberstopic.asp