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
>