Pages

c # function to test HHMM

function to test HHMM -- HoursMins using regular expression (REGEX)
private string TestHHMM()
{
string InputString = DateTime.Now.ToString("HHmm"); // "2200";
if (InputString.Length >= 2)
InputString = InputString.PadLeft(4, '0');
Regex RegexObj = new Regex("^([0-1]\\d
2[0-3])([0-5][0-9])$");
if (RegexObj.IsMatch(InputString))
Console.WriteLine("true");
else
Console.WriteLine("false");
return RegexObj.Replace(InputString, "$1:$2");
}

0 comment:

إرسال تعليق

Link With in

Related Posts Plugin for WordPress, Blogger...