I have a Unformatted String (Eg: Sundy/03-1 3-1949) I need to convert this to "dd/MM/yyyy".
My plan is to remove text, spaces, special characters and keep numbers only (Eg: Sundy/03-1 3-1949 --> 03131949)
Then convert the numbers to in date format.(Eg: Sundy/03-1 3-1949 --> 03131949 ---> 13/03/1949)
The Code I used
private void button1_Click(object sender, EventArgs e)
{
String stringWithDate = textBox1.Text.ToString();
if (stringWithDate.ToString() != null && !stringWithDate.ToString().Equals(""))
{
DateTime dts;
String str = stringWithDate.ToString();
str = Regex.Replace(str, @"[^\d]", "");
Console.WriteLine("String: " + stringWithDate.ToString() + "\n Removed Spaces: " + str);
if (DateTime.TryParseExact(str, "MMddyyyy", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dts))
{
String a = dts.ToString("MM/dd/yyyy");
stringWithDate = a;
Console.WriteLine("String: " + stringWithDate.ToString() + "\n Removed Spaces: " + str + "\n Date formatted: " + a + "\n");
label1.Text = (a);
}
}
}
The Output is not detecting all types. Is there a way to pass everything

This will get some of the missing values, but one very important thing to understand is there is no computer program anywhere that can understand any date format a human might input. You need to do better on the front end, guiding humans to input reasonable, consistent, and --above all-- unambiguous values.
I'd further change this to extract some smaller methods:
One advantage here is you can limit your tinkering to just the
NormalizeDateInput()method.