4.7.2- Returning the Length of a String
by NT Community Manager.
|
| << 4.7.1- Changing the Case of a String | Chapter4 | 4.7.3- Pruning the Beginning or End of a String >> |
Returning the Length of a String
The Len function is used to return the length of a string – that is, the number of characters. You can use itin the following way:
Len(string)
This function only takes one argument, namely the stringthat you are measuring:
intHowLong = Len("HowLongIsAPieceOfString?")
In this example, there are 24 characters in this string, and so intHowLong is assigned the value 24. Anysymbols, punctuation, and spaces within the string are valid characters, andtherefore they are counted in the length of the string. You can also supply avariable name to the Len function; in this case,it will measure the contents of the named variable:
strText = "HowLongIsAPieceOfString?"
intHowLong = Len(strText)
In this example, the Lenfunction would again return the value 24. Later on, we'll use this function inan example that loops through a string, character by character – the functionis used to tell us when we've reached the end of the string.
| << 4.7.1- Changing the Case of a String | Chapter4 | 4.7.3- Pruning the Beginning or End of a String >> |

RSS

