Trimming and Concatenating Expressions

When you specify expressions containing multiple fields, they might not display the way you want because of unwanted spacing. You can trim fields and concatenate expressions to remove the unwanted spacing. For example, suppose you want to display an address line containing the city name, region, and postal code. Specifying separate fields that contain the city name, region, and postal code in a row might produce display unwanted spaces between each value.

Trimming Fields and Concatenating Expressions

You can trim and concatenate expressions containing multiple fields with values that vary into a single expression. You can trim fields by enclosing the ALLTRIM( ) function around each field name, insert punctuation or desired space enclosed by quotation marks (" "), and concatenate expressions using a plus sign (+) between each expression.

The space required by each value can vary. However, if the value lengths in the fields do not vary, for example, postal codes or abbreviations, you can enclose only the field name that varies using ALLTRIM( ) as shown in the following example:

ALLTRIM(city) + ", " + region + "  " + postal_code

Note

Space, rather than a comma, enclosed by quotation marks separate the region and the postal code.

For more examples, see the sample report Invoice.frx in the Visual FoxPro directory, ...\Samples\Solution\Reports.

Trimming and Concatenating Expressions Quickly

When you do not need or want to include punctuation in the expression, you can trim or concatenate expressions quickly by inserting commas (,) between each expression. The value of the expression preceding the comma is trimmed.

Note

Provided that the trimmed value has a length greater than zero, you can use semicolons (;) to place the trimmed expression on a new line.

The following example shows a trimmed and concatenated expression containing multiple fields for a mailing address:

contact_name; address; city, region, postal_code

See Also

Tasks

How to: Trim and Concatenate Fields

Other Resources

Building Expressions