VB中的len的疑问。

来源:百度知道 编辑:UC知道 时间:2024/06/15 05:20:33
MyString = "this is a small test"
MyLen = Len(MyString)
答案是多少?
我看一本书说是21?为什么??
Type CustomerRecord ' Define user-defined type.
ID As Integer ' Place this definition in a
Name As String * 10 ' standard module.
Address As String * 30
End Type

Dim Customer As CustomerRecord ' Declare variables.
Dim MyInt As Integer, MyCur As Currency
Dim MyString, MyLen
MyString = "Hello World" ' Initialize variable.
MyLen = Len(MyInt) ' Returns 2.
MyLen = Len(Customer) ' Returns 42.
MyLen = Len(MyString) ' Returns 11.
MyLen = Len(MyCur) ' Returns 8.

20是对的,21可能是句子后面还有个句号,this is a small test.
说字符串末尾是\0的,那是C,不是VB

this is a small test
应该是21,对的。一共是20个字符,但是在字符串的结尾处要加一个字符串结束标记‘\0’,正好是21个。

21应该是对的。不过有的机子上可能是机子参数的问题而倒至等于20.我机子上曾经有一次就是,怎么算e答案都是1.

我用VB6测试是输出20啊...