在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);
   }
}

更新日期:2020-06-21

558次瀏覽

開啟你的職業生涯

完成課程獲得認證

立即開始
廣告