Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reversing the order of clauses in a string

Tags:

c#

asp.net

If my string has values as:

myString = "Good Morning,Good Night";

and I want to reverse the values in it like as follows:

I want the final values in the myString as:

myString = "Good Night,Good Morning";

How do I achieve this?

like image 884
Serenity Avatar asked Jan 26 '26 20:01

Serenity


1 Answers

How about:

string myString = "Good Morning,Good Night";
string[] subStrings = myString.Split(',');
myString = string.Join(",", subStrings.Reverse());

Or if you like to write these as one liners:

myString = string.Join(",", myString.Split(',').Reverse());
like image 196
Øyvind Bråthen Avatar answered Jan 29 '26 09:01

Øyvind Bråthen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!