String

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 11 (Modified)


String (expression{; format}) String

ParameterTypeDescription
expressionExpression for which to return the string form
(can be Real, Integer, Long Integer, Date, Time
String, Text or Boolean)
formatString | NumberDisplay format
Function resultStringString form of the expression

Description

The String command returns the string form of the numeric, Date, Time, string or Boolean expression you pass in expression.

If you do not pass the optional format parameter, the string is returned with the appropriate default format. If you pass format, you can force the result string to be of a specific format.

Numeric Expressions

If expression is a numeric expression (Real, Integer, Long Integer), you can pass an optional string format. Following are some examples:

ExampleResult
String(2^15) ` Use default format32768 (Default format used here)
String(2^15;"###,##0 Inhabitants")32,768 Inhabitants
String(1/3;"##0.00000")0.33333
String(1/3) ` Use default format0.3333333333333333 (Default format used here)
String(Arctan(1)*4)3.1415926535897931 (Default format used here)
String(Arctan(1)*4;"##0.00")3.14
String(-1;"&x")0xFFFFFFFF
String(-1;"&$")$FFFFFFFF
String(0 ?+ 7;"&x")0x80
String(0 ?+ 7;"&$")$80
String(0 ?+ 14;"&x")0x4000
String(0 ?+ 14;"&$")$4000
String(Num(1=1);"True;;False")True
String(Num(1=2);"True;;False")False

The format is specified in the same way as it would be for a number field on a form. See the 4D Design Reference manual for more information about formatting numbers. You can also pass the name of a custom style in format. The custom style name must be preceded by the "|" character.

Date Expressions

If expression is a Date expression, the string is returned using the default format specified in the system.

In the format parameter, you can pass one of the following constants ("Date Display Formats" theme):

NumberConstant Example
1 System date short 12/29/2006
2 System date abbreviated Sun, Dec 29, 2006
3 System date long Sunday, December 29, 2006
4 Internal date short special12/29/06 or 12/29/1896 or 12/29/2096
5 Internal date long December 29, 2006
6 Internal date abbreviated Dec 29, 2006
7Internal date short12/29/2006
8ISO Date Time2006-12-29T00:00:00
100Blank if null"" instead of 0

Notes:

The ISO Date Time format corresponds to the ISO8601 standard. This format contains a date and a time. For example, the date May 31, 2006 at 1:20 p.m. is written 2006-05-31T13:20:00. It is used for XML processing and with Web services. 4D does not permit storing a date and a time in a single field. However, it is possible to handle dates in this format using the String command.

The Blank if null constant must be added to the format; it indicates that in the case of a null value, 4D must return an empty string instead of zeros.

These examples assume that the current date is 12/29/2006:

   $vsResult:=String(Current date)   ` $vsResult gets "12/29/06"
   $vsResult:=String(Current date;Month Date Year)   ` $vsResult gets "December 29, 2006"
   $vsResult:=String(Current date;ISO Date Time)   ` $vsResult gets "2006-12-29T00:00:00"

Time Expressions

If expression is a Time expression, the string is returned using the default HH:MM:SS format. In the format parameter, you can pass one of the following constants ("Time Display Formats" theme):

NumberConstant Example
1 HH:MM:SS 01:02:03
2 HH:MM 01:02
3 Hour Min Sec 1 hour 2 minutes 3 seconds
4 Hour Min 1 hour 2 minutes
5 HH MM AM PM 1:02 AM
6 MM SS62:03
7Min Sec62 minutes 3 seconds
8ISO Date Time0000-00-00T01:02:03
9System time short01:02:03
10System time long abbreviated10203 AM (Mac only)
11System time long1:02:03 AM HNEC (Mac only)
100Blank if null"" instead of 0

Notes:

For more information about the ISO Date Time format, refer to the note above.

The Blank if null constant must be added to the format; it indicates that in the case of a null value, 4D must return an empty string instead of zeros.

These examples assume that the current time is 5:30 PM and 45 seconds:

   $vsResult:=String(Current time)   ` $vsResult gets "17:30:45"
   $vsResult:=String(Current time;Hour Min Sec)   ` $vsResult gets "17 hours 30 minutes 45 seconds"

String Expressions

If expression is of the String or Text type, the command returns the same value as the one passed in the parameter. This can be useful more particularly in generic programming using pointers.

In this case, the format parameter, if passed, is ignored.

Boolean Expressions

If expression is of the Boolean type, the command returns the string "True" or "False" in the language of the application (for example, "Vrai" or "Faux" in a French version of 4D).

In this case, the format parameter, if passed, is ignored.

See Also

Date, Num, Time string.


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next