當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


VB.NET String Join()用法及代碼示例

Join() 方法用於連接字符串數組的所有元素,在每個元素之間使用指定的分隔符。

用法:

Function Join(ByVal separator as String, ByVal arr() as String) as String

參數:

  • Separator:指定分隔符
  • Arr:指定字符串數組

返回值:它返回連接的字符串。

程序/源代碼:

下麵給出了演示 String 類的 Join() 方法的源代碼。給定的程序已成功編譯並執行。

'VB.NET program to demonstrate the 
'Join() method of String class.

Imports System

Module Module1
    Sub Main()

        Dim str() As String = {"Hello", "how", "are", "you"}
        Dim result As String

        result = String.Join("_", str)
        Console.WriteLine("Result:#{0}#", result)

    End Sub
End Module

輸出:

Result:#Hello_how_are_you#
Press any key to continue . . .

說明:

在上麵的程序中,我們創建了一個包含 Main() 函數的模塊 Module1。 Main() 函數是程序的入口點。

在 Main() 函數中,我們創建了一個包含一些字符串元素的字符串數組。在這裏,我們使用 String 類的 Join() 方法連接所有字符串數組元素並使用指定的分隔符連接每個字符串元素,並在控製台屏幕上打印連接後的字符串。





相關用法


注:本文由純淨天空篩選整理自 VB.Net program to demonstrate the Join() method of String class。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。