Page

4.7.2- Returning the Length of a String

  by NT Community Manager.
Last Updated  by NT Community Manager.  

PublicCategorized as 04. Variables.

Not tagged.
<< 4.7.1- Changing the Case of a StringChapter44.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 StringChapter44.7.3- Pruning the Beginning or End of a String >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |