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


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

Mid() 函數用於從給定的指定字符串中提取子字符串。

用法:

Mid(str, pos, n)

參數:

  • Str:指定字符串
  • Pos:position 從哪裏提取子字符串。
  • N:Number 字符從字符串中提取。

返回值:

Mid() 函數將返回一個子字符串值。

程序/源代碼:

下麵給出了演示 Mid() 函數的源代碼。給定的程序已成功編譯並執行。

'VB.Net program to demonstrate the Mid() function.

Module Module1

    Sub Main()
        Dim str1 As String = "I love india"
        Dim str2 As String = ""

        str2 = Mid(str1, 3, 4)
        Console.WriteLine("Sub-string is:{0}", str2)
    End Sub

End Module

輸出:

Sub-string is:love
Press any key to continue . . .

說明:

在上麵的程序中,我們創建了一個包含 Main() 方法的模塊 Module1。在 Main() 方法中,我們創建了兩個變量 str1 和 str2,這裏變量 str1 初始化為“我愛印度”,變量 str2 初始化為空字符串。

str2 = Mid(str1, 3, 4)

在上麵的代碼中,我們從 str1 中提取了子字符串並將其分配給 str2。然後我們在控製台屏幕上打印提取的子字符串。





相關用法


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