String

Description

Formats data as a string according to a specified display format mask. You can convert and format date, DateTime, numeric, and time data. You can also apply a display format to a string.

Syntax

String ( data {, format } )

Argument

Description

data

The data you want returned as a string with the specified formatting. Data can have a date, DateTime, numeric, time, or string datatype.

format (optional)

A string of the display masks you want to use to format the data. The masks consist of formatting information specific to the datatype of data. If data is type string, format is required.

The format string can consist of more than one mask, depending on the datatype of data. Each mask is separated by a semicolon. See Usage for details on each datatype.

Returns

String. Returns data in the specified format if it succeeds and the empty string (“”) if the datatype of data does not match the type of display mask specified or format is not a valid mask.

Usage

For date, DateTime, numeric, and time data, the system’s default format is used for the returned string if you do not specify a format. For numeric data, the default format is the [General] format.

For string data, a display format mask is required. (Otherwise, the function would have nothing to do.)

The format can consist of one or more masks:

A format can include color specifications.

If the display format does not match the datatype, the attempt to apply the mask produces unpredictable results.

For information on specifying display formats, see the User’s Guide.

Examples

Example 1

This expression returns Jan 31, 2005:

String(2005-01-31, "mmm dd, yyyy")

Example 2

This expression returns Jan 31, 2005 6 hrs and 8 min:

String(2005-01-31 06:08:00, 'mmm dd, yyyy, h "hrs 
and" m "min"')

Example 3

This expression:

String(nbr, "0000;(000);****;empty")

Example 4

returns:

Example 5

This expression returns A-B-C:

String("ABC", "@-@-@")

Example 6

This expression returns A*B:

String("ABC", "@*@")

Example 7

This expression returns ABC:

String("ABC", "@@@")

Example 8

This expression returns a space:

String("ABC", " ")

Example 9

This expression returns 6 hrs and 8 min:

String(06:08:02,'h "hrs and" m "min"')

Example 10

This expression returns 08:06:04 pm:

String(20:06:04, "hh:mm:ss am/pm")

Example 11

This expression returns 8:06:04 am:

String(08:06:04, "h:mm:ss am/pm")

Example 12

This expression returns 6:11:25.300000:

String(6:11:25.300000, "h:mm:ss.ffffff")