在 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 次瀏覽量

開啟 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.