Len() - 返回字符串中的字符数。
Dim str As String
str = "Hello"
MsgBox Len(str) ' 显示 5
Left() - 返回字符串左侧指定数量的字符。
Dim str As Stringstr = "Hello World"
MsgBox Left(str, 5) ' 显示 "Hello"
Right() - 返回字符串右侧指定数量的字符。
Dim str As Stringstr = "Hello World"
MsgBox Right(str, 5) ' 显示 "World"
Mid() - 从指定位置开始返回字符串中指定数量的字符。
Dim str As String
str = "Hello World"
MsgBox Mid(str, 7, 5) ' 显示 "World"
LCase() - 将字符串中的所有大写字母转换为小写。
Dim str As String
str = "HELLO"
MsgBox LCase(str) ' 显示 "hello"
UCase() - 将字符串中的所有小写字母转换为大写。
vb
Dim str As String
str = "hello"
MsgBox UCase(str) ' 显示 "HELLO"
LTrim() - 去除字符串左侧的空格。
vb
Dim str As String
str = " Hello"
MsgBox LTrim(str) ' 显示 "Hello"
RTrim() - 去除字符串右侧的空格。
vb
Dim str As String
str = "Hello "
MsgBox RTrim(str) ' 显示 "Hello"
Trim() - 去除字符串两侧的空格。
vb
Dim str As String
str = " Hello "
MsgBox Trim(str) ' 显示 "Hello"
Instr() - 返回一个字符串在另一个字符串中首次出现的位置。
Dim str1 As String, str2 As String
str1 = "Hello World"
str2 = "World"
MsgBox Instr(str1, str2) ' 显示 7
Replace() - 在字符串中替换指定的子字符串。
vb
Dim str As String
str = "Hello World"
MsgBox Replace(str, "World", "VB6") ' 显示 "Hello VB6"
这只是 VB6 中可用的一些基本字符串函数。VB6 还提供了其他功能和函数,可以用于更复杂的字符串操作。