Left$函数
用于从字符串的左侧提取指定字符串的函数。
格式
Left$ (字符串, 字符数)
参数
- 字符串
- 是指从左侧复制指定字符串的源字符串。
- 字符数
- 直接以数值形式指定从字符串左侧复制的字符数。
返回值
从指定字符串的左侧提取指定的字符数进行返回。
说明
Left$用于从指定字符串的左侧提取字符数所示数量的字符并进行返回。使用Left$可返回指定字符串内的字符数所示数量的字符。
参阅
Asc、Chr$、InStr、Len、Mid$、Right$、Space$、Str$、Val
Left$函数使用示例
如下所示为分析字符串的程序示例。
Function ParsePartData(DataIn$ As String, ByRef PartNum$ As String, ByRef PartName$ As String, ByRef PartCount As Integer)
Integer pos
String temp$
pos = Instr(DataIn$, ",")
PartNum$ = Left$(DataIn$, pos - 1)
DataIn$ = Right$(datain$, Len(DataIn$) - pos)
pos = Instr(DataIn$, ",")
PartName$ = Left$(DataIn$, pos - 1)
PartCount = Val(Right$(datain$, Len(DataIn$) - pos))
Fend
如下所示为通过命令窗口使用Left$命令的示例。
> Print Left$("ABCDEFG", 2)
AB
> Print Left$("ABC", 3)
ABC