CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    9

    Regular Expressions

    Hi! Im wondering if someone could answer a really newbie question concerning regular expressions in c#. I have a string (stringPacket) containing an Ethernetpacket in hex and i want to put the first 6 characters in a variable called ethDestMac.

    So far i have:

    Regex regexPacket = new Regex(@"^(?<ethDestMac>[0-9a-f]{6})");
    Match oMatch=regexPacket.Match(stringPacket);
    ethDestMac = oMatch.Groups["ethDestMac"].ToString();

    But that doesnt give me the correct answer. Would very much appreciate if someone could push me in the right direction on how to get my program to work.

    Thanks!

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Regular Expressions

    You don't need a regular expression for this, you can do this by using normal string manipulation functions e.g.

    Code:
    string first6 = stringPacket.Substring(0,6);
    Darwen
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured