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