在VB中,字符串(String)函數可以用于處理和操作字符串數據。以下是一些常見的String函數用法:
示例:
Dim str As String = “Hello World”
Dim length As Integer = Len(str)
’ length的值為11
示例:
Dim str As String = “Hello World”
Dim subStr As String = Mid(str, 7, 5)
’ subStr的值為 “World”
示例:
Dim str As String = “Hello World”
Dim subStr As String = Left(str, 5)
’ subStr的值為 “Hello”
示例:
Dim str As String = “Hello World”
Dim subStr As String = Right(str, 5)
’ subStr的值為 “World”
示例:
Dim str As String = “Hello World”
Dim position As Integer = InStr(str, “o”)
’ position的值為 5
示例:
Dim str As String = “Hello World”
Dim newStr As String = Replace(str, “World”, “VB”)
’ newStr的值為 “Hello VB”
這些只是String函數的一些常見用法,還有其他更多的用法可以根據具體需求進行使用。