开发者

Need help with string manipulation please

开发者 https://www.devze.com 2023-02-09 04:45 出处:网络
If my string has values as :- my开发者_如何学GoString = \"Good Morning,Good Night\"; and I want to reverse the values in it like as follows:-

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号