Len函數

用於傳回字串的字元數。

格式
Len (字串)

參數

字串
指定字串運算式。

傳回值
用於以整數值傳回作為Len命令的引數而賦予的字串字元數。

說明
Len用於以整數值(0~255)傳回指定字串的字元數。(字串的字數限制範圍為0~255。)

參照
Asc、Chr$、InStr、Left$、Mid$、Right$、Space$、Str$、Val

Len函數範例
以下是用於分析字串的程式範例。

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

這是其它在命令視窗中使用Len命令的範例。

> ? len("ABCDEFG")
7

> ? len("ABC")
3

> ? len("")
0
>