using System.Text.RegularExpressions;
public static void Main()
var c = new ConfigParser();
string pw = "fg%|uy|" + '\x11' +'\x14' + "|hj" +'\x18' +"khg";
Console.WriteLine("note: Password include non pintable characters and the separator |");
Console.WriteLine("firstname: {0}", c.FirstName);
Console.WriteLine("lastname: {0}", c.LastName);
Console.WriteLine("UserId: {0}", c.UserId);
Console.WriteLine("Password: {0}", c.Password);
Console.WriteLine("date: {0}", c.Date);
public static string Generate(string password)
string text = string.Format(@"FirstName=Elmer|LastName=Fudd|UserId=EFudd|Password={0}|Date=7/29/2016", password);
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserId { get; set; }
public string Password { get; set; }
public string Date { get; set; }
public ConfigParser(string text)
private static string pattern = @"
^FirstName=(?<firstname>\w+) \|
LastName=(?<lastname>\w+) \|
Password=(?<pasword>.+) \|
private Regex regex = new Regex(pattern,
| RegexOptions.ExplicitCapture
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
public void Parse(string text)
Console.WriteLine("text: {0}",text);
Match m = regex.Match(text);
FirstName = m.Groups["firstname"].ToString();
LastName = m.Groups["lastname"].ToString();
UserId = m.Groups["userid"].ToString();
Password = m.Groups["pasword"].ToString();
Date = m.Groups["date"].ToString();