I have a Visual Studio 2008 C# .NET 3.5 application where I need to parse a macro.
Given a serial serial number that is N digits long, and a macro like %SERIALNUMBER3%, I would like this parse method to return only the first 3 digits of the serial number.
string serialnumber = "123456789";
string macro = "%SERIALNUMBER3%";
string parsed = SomeParseMethod(serialnumber, macro);
parsed = "123"
Given `%SERIALNUMBER7%, return the first 7 digits, etc..
I can do this using String.IndexOf and some complexity, but I wondered if there was a simple method. Maybe using a Regex replace.
What’s the simplest method of doing this?
1 Answer