LEN |
LEN(expression) |
Returns the number of characters in a string (Long). |
string | The text string expression (String). |
REMARKS |
* When VBA stores a string in memory, it always stores the length of the string in a long integer at the start of the string. * This function retrieves this value and is therefore faster than having to examine the actual characters. * This function is useful for determining whether a string is a zero-length string ("") and should be used before comparing to a zero length string. * If "string" = "" (zero length string), then a zero length string is returned. * If "string" is vbNullString, then a zero length string is returned. * This function can also be used to determine the number of bytes used to store a variable. * You can use the LEFT function to return a substring from the left of a string. * You can use the LENB function to use with byte data. * You can use the MID Function to return a substring from the middle, left or right of a string. * You can use the RIGHT function to return a substring from the right of a string. * The equivalent Excel function is LEN * The equivalent .NET function is [[Microsoft.VisualBasic.Strings.Len]] * For the Microsoft documentation refer to learn.microsoft.com |
Debug.Print Len("sometext") '= 8
Debug.Print Len("length of text") '= 14
Debug.Print Len("") '= 0
Debug.Print Len("true") '= 4
Debug.Print Len("false") '= 5
Debug.Print Len(true) ' compile error
Debug.Print Len(100) ' compile error
Dim lResult As Long
lResult = Len("development")
Debug.Print lResult '= 11
lResult = Len("")
Debug.Print lResult '= 0
lResult = Len(vbNullString)
Debug.Print lResult '= 0
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top