我找不到任何。有吗?谷歌没有帮我,因为它不区分大小写,认为我在寻找"基本"命令。
使用LEN(表达式(,其中表达式可以是任何字符串或字符串变量
示例:
X = LEN("Jack Daniels") >>> X contains 12
或
strX = "Jack"
X = LEN(strX) >>> X contains 4
我所知道的所有Basic方言都有一个返回字符串表达式长度的len
函数。示例:
- Apple//Integer基本
- Visual Basic 6
- Visual Basic.NET
- http://www.fact-index.com/b/ba/basic_programming_language.html
在Visual Basic.NET中,您也可以使用字符串的.Length
属性,但该属性对于Nothing
值的行为不同:Len((函数与string.Length属性;选择哪个?
使用Len
Dim YourString as String
Dim CharCount as Integer
YourString ="MyString"
CharCount = LEN(YourString)
msgbox "There are " & CharCount & " Characters in mystring"
如果你的意思是想计算中特定字符的数量,你可以这样做:
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"
是的,看看这个例子:
' Initializes variable.
Dim TestString As String = "Hello World"
' Returns 11.
Dim TestLen As Integer = Len(TestString)
所以TestString=Hello World,而TestLen=11,因为Hello World中有11个字符
conta = strlen(name_of_variable)
strlen
给出给定整数的变量的字符数