Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

Is there equivalent of sscanf function in .NET?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 03 May 2005 22:22 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.