Return to Snippet

Revision: 19411
at October 22, 2009 22:11 by rtipton


Initial Code
using System;
using System.Text;
using System.Text.RegularExpressions;

namespace RegularExpressions
{
    public class Program
    {
        public static void Main()
        {
            //-- Take input value and if it is in lastname, firstname format echoes firstname lastname to the console
            string userName = Console.ReadLine();
            Regex re = new Regex("(\\w+),\\s(\\w+)");
            userName = re.Replace(userName, "$2 $1");
            Console.WriteLine(userName);

            //-- Take input value and if it is in mm/dd/yyyy format echoes yyyy/mm/dd to the console
            string curDate = Console.ReadLine();
            Regex reDate = new Regex("(\\d{2})/(\\d{2})/(\\d{4})");
            curDate = reDate.Replace(curDate, "$3/$1/$2");
            Console.WriteLine(curDate);
        }
    }
}

Initial URL


Initial Description


Initial Title
Regular Expressions Sample

Initial Tags
regex

Initial Language
C#