473,408 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Is there equivalent of sscanf function in .NET?

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
Nov 17 '05 #1
3 1982
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[i] = Convert::ToByte(macParts[i], 16);
}

return macBytes;
}
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Nov 17 '05 #2
Thank you

"Tomas Restrepo (MVP)" wrote:
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[i] = Convert::ToByte(macParts[i], 16);
}

return macBytes;
}
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/

Nov 17 '05 #3
Steve wrote:
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...mberstopic.asp
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ishekara | last post by:
Hi, As per the msdn knowledge base.. i find the following "In an application developed with Microsoft C or C/C++, the sscanf() function is a good alternative to the atof() function to convert...
6
by: Rob Thorpe | last post by:
Given the code:- r = sscanf (s, "%lf", x); What is the correct output if the string s is simply "-" ? If "-" is considered the beginning of a number, that has been cut-short then the...
10
by: baumann | last post by:
hi, 1) first test program code #include <stdio.h> int main(void) { char * file = "aaa 23 32 m 2.23 ammasd"; int i2,i3;
7
by: nick | last post by:
is it similar to scanf? when i use scanf it can read the words in the screen automatically one after another.i use a char array to store the string,then use sscanf to read the words,but it just...
8
by: Artemio | last post by:
Dear folks, I need some help with using the sscanf() function. I need to parse a string which has several parameters given in a "A=... B=... C=..." way, and each has a different type (one is a...
20
by: AMP | last post by:
Hello, Anybody know if anything exists like sscanf in c. I found a few things OL but most were pretty old. Maybe something has come along since 2004? Thanks Mike
1
by: ziroi | last post by:
Hello! I am new here to the forums and still learning C. I understand your policies on coursework, but I have an error that I've run around and around and can't figure out where my problem is...
7
by: Joachim Schmitz | last post by:
Hi folks What would be the expected and correct output of the following #include <stdio.h> int main (void) { char buffer1 = "(10,20,30)"; char buffer2 = "(10,20,30 )"; /* add two...
4
by: aj | last post by:
Can someone explain why this example works: bool SomeFunction(const char * ipIpAddress, int &opOct1, int &opOct2, int &opOct3, int &opOct4) { int b1, b2, b3, b4; unsigned char c;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.