C# 程式,用於反轉字串中的單詞
假設以下字串為 −
Hello World
反轉字串後,單詞應該如下所示 −
olleH dlroW
示例
使用 reverse() 方法並嘗試以下程式碼來反轉字串中的單詞。
using System; using System.Linq; class Demo { static void Main() { // original string string str = "Hello World"; // reverse the string string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray()))); Console.WriteLine(res); } }
輸出
olleH dlroW
廣告