String 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.