Click or drag to resize

Trim Function

X#
Remove trailing spaces from a string.

Namespace:  XSharp.VFP
Assembly:  XSharp.VFP (in XSharp.VFP.dll) Version: 2.19
Syntax
 FUNCTION Trim(
	Expression AS STRING,
	Flags AS LONG,
	TrimChars PARAMS STRING[]
) AS STRING
Request Example View Source

Parameters

Expression
Type: String
Specifies an expression to remove trailing spaces or 0 bytes from
Flags
Type: Long
Specifies if trimming is case-sensitive when one or more parse characters (cParseChar, cParseChar2, … are included. Trimming is case-sensitive if nFlags is zero or is omitted. Trimming is case-insensitive if nFlags = 1.
TrimChars
Type: String
Specifies one or more character strings that are trimmed from the beginning of cExpression. If cParseChar isn't included, then leading spaces or 0 bytes are removed from Expression.

Return Value

Type: String
cString with the trailing spaces removed.
If cString is a NULL_STRING or all spaces, Trim() returns a NULL_STRING.
Remarks
Trim() is used to format strings by deleting trailing spaces while concatenating strings.
This is typically the case with database fields which are stored in fixed-width format.
For example, you can use Trim() to concatenate first and last name fields to form a name string. Trim() is related to LTrim(), which removes leading spaces, and AllTrim(), which removes both leading and trailing spaces.
The inverse of AllTrim(), LTrim(), and Trim() are the PadC(), PadR(), and PadL() functions, which center, right-justify, or left-justify strings by padding them with fill characters.
Examples
This is a function in which Trim() formats city, state, and zip code fields for labels or form letters:
X#
1FUNCTION CityState(cCity, cState, cZip)
2    RETURN Trim(cCity) + ", " ;
3                + Trim(cState) + "  " + cZip
To complete the example the function, CityState(), displays a record from CUSTOMER.DBF:
X#
1USE customer INDEX custname NEW
2SEEK "Kate"
3? CityState(City, State, ZipCode)
4// Athens, GA 10066
See Also