If my string has values as :-
my开发者_如何学GoString = "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? Any help will be appreaciated. Thanks. :)
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());
var newString = string.Join(",", myString.Split(',').Reverse());
I'm guessing that what you're trying to do is split the string on commas. Something like this:
string myString = "Good Morning,Good Night";
string[] split = myString.Split(',');
myString = split[1] + ',' + split[0];
精彩评论