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


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

Concat() 方法用於連接兩個字符串並將連接後的字符串返回給調用函數。

用法:

Function Concat (ByVal str1 as String, ByVal str2 as String) as String

參數:

  • Str1:要連接的字符串。
  • Str2:要連接的字符串。

返回值:它返回基於指定字符串的連接字符串。

程序/源代碼:

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

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

Imports System

Module Module1
    Sub Main()
        Dim str1 As String = "Hello "
        Dim str2 As String = "World "
        Dim str3 As String

        str3 = String.Concat(str1, str2)

        Console.WriteLine("Str1:{0}", str1)
        Console.WriteLine("Str2:{0}", str2)
        Console.WriteLine("Str3:{0}", str3)
    End Sub
End Module

輸出:

Str1:Hello
Str2:World
Str3:Hello World
Press any key to continue . . .

說明:

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

在 Main() 函數中,我們創建了三個字符串 str1、str2 和 str3。在這裏,我們將兩個字符串 str1 和 str2 連接起來,並將連接後的字符串分配給 str3。之後,我們在控製台屏幕上打印了所有字符串。





相關用法


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