A Regular Expression is probably the best way to go. Personally, I dislike the syntax, it looks like a cat has walked across the top rows of the keyboard. Fortunately, if your string format is constant, you can simply split the string on the first digit found and return the result as a value Tuple (string month, string date)
. Something like this.
private static (string month, string date) SplitMonthAndDayOfMonth(string s)
{
for (int i = 0; i < s.Length; i++)
{
if (char.IsDigit(s[i]))
{
return (s.Substring(0, i), s.Substring(i));
}
}
return (string.Empty, string.Empty);
}
private static void Main(string[] args)
{
string s = "Jan30";
var (month, day) = SplitMonthAndDayOfMonth(s);
Console.WriteLine($"Month is {month} date is {day}");
Console.ReadLine();
}