我找不到任何东西。有吗?谷歌没有帮助我,因为它不区分大小写,并认为我在寻找“基本”命令。
答案 0 :(得分:10)
使用LEN(表达式),其中表达式可以是任何字符串或字符串变量
示例:
X = LEN("Jack Daniels") >>> X contains 12
或
strX = "Jack"
X = LEN(strX) >>> X contains 4
答案 1 :(得分:6)
我所知道的所有基本方言都有len
函数,它返回字符串表达式的长度。例子:
在Visual Basic .NET中,您还可以使用字符串的.Length
属性,但该属性对Nothing
值的行为有所不同:Len() function vs String.Length property; which to choose?
答案 2 :(得分:2)
使用 Len
Dim YourString as String
Dim CharCount as Integer
YourString ="MyString"
CharCount = LEN(YourString)
msgbox "There are " & CharCount & " Characters in mystring"
答案 3 :(得分:0)
conta = strlen(name_of_variable)
strlen
给出给定整数
答案 4 :(得分:0)
如果你想要计算a中特定字符的数量,你可以这样做:
Dim YourString as String
Dim CharCount as Integer
Dim MyChr as Char
Dim chrl as Char
YourString ="MyString"
MyChr ="A"
CharCount = 0
For i = 1 To Len(YourString)
chrl = Mid(YourString, i, 1)
if UCase(chrl) = UCase(MyChr) then
CharCount = CharCount + 1
end if
next i
msgbox "There are " & CharCount & " " & MyChr & " Characters in mystring"
答案 5 :(得分:0)
是的,请看这个例子:
' Initializes variable.
Dim TestString As String = "Hello World"
' Returns 11.
Dim TestLen As Integer = Len(TestString)
所以TestString = Hello World,TestLen = 11因为Hello World中有11个字符。