Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

LEN()

This function tells you how long a string is.

Usage

nStringLength = LEN( cString )

That’s it, just the length of the string you pass it.

Except for one thing. There’s a gotcha when you use LEN() on a character field (it works fine on memo fields). Fields in FoxPro are fixed-length, so strings that don’t fill the allocated space get filled with trailing blanks. When you apply LEN() to a character field, you get back the defined size of the field, not the size of the actual contents. Apply TRIM() or ALLTRIM() before LEN() if you want to know how many characters you’ve actually put in a field.

Like most of the string-handling functions, LEN() has a double-byte alternative, LENC(), useful for handling strings in languages that have larger character sets.

Example

? LEN("abcdef")      && returns 6
? LEN(LastName)      && returns defined length of LastName field
? LEN(TRIM(LastName)) && returns length of LastName for
                      && current record

See Also

AllTrim(), FSize(), LenC(), Trim()