在C#中反轉給定字串中的單詞
假設如下字串:
Welcome
反轉字串後,單詞應如下所示:
emocleW
使用reverse()方法,嘗試以下程式碼反轉字串中的單詞:
示例
using System; using System.Linq; class Demo { static void Main() { string str = "Welcome"; // reverse the string string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray()))); Console.WriteLine(res); } }
廣告