I have a string let say,
string temp1 = "25 10 2012"
but I want this,
"2012 10 25"
what would be the best way of doing it. format will always be like this.
Looks like its a date. You can parse the string to DateTime, using DateTime.ParseExact and then use .ToString to return formatted result.
DateTime dt = DateTime.ParseExact(temp1, "dd MM yyyy", CultureInfo.InvariantCulture);
Console.Write(dt.ToString("yyyy MM dd"));
You may use that DateTime object later in your code, and also apply different formatting (if you need)
try this split string and reverse array , and this will work for string of any length ...
string[] myArray = temp1.Split(' ');
Array.Reverse( myArray );
string reverse =string.Join(" ", myArray );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With