### Length (str)

Length and Len (str) are equivalent functions. However, Length is preferred in Crystal syntax whereas Len is preferred in Basic syntax.

##### Arguments

str is a text value.

##### Returns

Whole Number

##### Action

Length returns the number of characters in a text string that you enter into the formula, or in a text string stored as a value in a data field.

Note: Text strings must be enclosed in either double or single quotation marks (" " or ` '). Any blank spaces are included as part of the character count.

##### Typical uses

Use this function any time you have a manipulation, comparison, or calculation that is dependent on the length of a text string.

##### Examples

The following examples are applicable to both Basic and Crystal syntax, although Len is preferred in the latter:

`Length("Account")`

Returns 7.

`Length("Text_String")`

Returns 11.

`Length("__Center__")`

Returns 10.

`Length(ToText({orders.ORDER AMOUNT}))`

Returns 9, where {orders.ORDER AMOUNT} is 14233.08, and ToText ({orders.ORDER AMOUNT}) returns the String "14,233.08". Here, the comma and period have been specified in the Number format for the formula field as the thousands and decimal separators respectively,

`Length(ToText({orders.ORDER AMOUNT}, 2, "", "."))`

Returns 8 where {orders.ORDER AMOUNT} = 14233.08, and ToText ({orders.ORDER AMOUNT}, 2, "", ".") returns the String "14233.08". Here, the null character and period have been specified in the Number format for the formula field as the thousands and decimal separators respectively.

`Length("BOB")`

Returns 3.

`Length("SMITH")`

Returns 5.

`Length("BOB SMITH")`

Returns 9. (The blank space between BOB and SMITH is counted as a character.)

`Length({customer.CUSTOMER NAME})`

The length of the text string stored as a value in {customer.CUSTOMER NAME}.

The following examples are applicable to Crystal syntax.

`{customer.CUSTOMER NAME}[Length({customer.CUSTOMER NAME})-2]`

Returns the third character from the right in the Customer Name. This can also be used to extract a substring from a String that always starts at a fixed position from the end of the String.

In the following example, an address line contains the province name and postal code. Full province names are of different lengths, but the first character of the postal code is always the seventh from the last character. The formula determines the length of the address line, subtracts 7 from it, and uses the result to identify the first character of the postal code in the address line.

Local StringVar addressLine;
Local NumberVar addrLength;
addressLine := "British Columbia V6X 3W2";
addrLength := Length (addressLine);
addressLine [addrLength-7+1 to addrLength]

###### Related topics

Formula 14

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com