字串 Join() 方法


字串中的 Join () 方法使用每個元素之間的指定分隔符,連線字串陣列的所有元素。

在下面的示例中,我們有一個多行字串,並且將分隔符設定為“
” -

String.Join("
", starray);

示例

以下是完整示例 -

 即時演示

using System;

namespace StringApplication {

   class StringProg {
      static void Main(string[] args) {
         string[] starray = new string[]{"Down the way nights are dark",
            "And the sun shines daily on the mountaintop",
            "I took a trip on a sailing ship",
            "And when I reached Jamaica",
            "I made a stop"};

         string str = String.Join("
", starray);          Console.WriteLine(str);       }    } }

輸出

Down the way nights are dark
And the sun shines daily on the mountain top
I took a trip on a sailing ship
And when I reached Jamaica
I made a stop

更新於: 27-Mar-2020

570 次瀏覽

開啟你的 職業

完成課程獲得認證

開始使用
廣告
© . All rights reserved.