Is there equivalent of sscanf function in .NET?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Steve,
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.

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 = Convert::ToByte(macParts, 16);
}

return macBytes;
}
 
Thank you

Tomas Restrepo (MVP) said:
Steve,
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.

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 = Convert::ToByte(macParts, 16);
}

return macBytes;
}
 
Steve said:
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.



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
 
Back
Top