String

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 2004.5 (Modified)


String (expression{; format}) String

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

Description

The String command returns the string form of the numeric, Date, or Time 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 4th Dimension 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 country format (i.e., MM/DD/YY for the U.S. English language version).

You can pass an optional numeric format from the following table:

Format Name Example
1 Short 12/29/96
2 Abbreviated Sun, Dec 29, 1996
3 Long Sunday, December 29, 1996
4 MM/DD/YYYY 12/29/96 or 12/29/1896 or 12/29/2096
5 Month Date, Year December 29, 1996
6 Abbr: Month Date, Year Dec 29, 1996
7MM/DD/YYYY Forced12/29/1996
8ISO Date Time1996-06-12T00:00:00

4D provides the following predefined constants:

ConstantTypeValue
ShortLong Integer1
AbbreviatedLong Integer2
LongLong Integer3
MM DD YYYYLong Integer4
Month Date YearLong Integer5
Abbr Month DateLong Integer6
MM DD YYYY ForcedLong Integer7
ISO Date TimeLong Integer8

Note: 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. 4th  Dimension 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.

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

   $vsResult:=String(Current date)   ` $vsResult gets "12/29/96"
   $vsResult:=String(Current date;Month Date Year)   ` $vsResult gets "December 29, 1996"
   $vsResult:=String(Current date;ISO Date Time)   ` $vsResult gets "1997-03-04T00:00:00"

Time Expressions

If expression is a Time expression, the string is returned using the default HH:MM:SS format. You can pass an optional numeric format from the following table:

Format Name 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 H:MM AM/PM 1:02 AM

4D provides the following predefined constants:

ConstantTypeValue
HH MM SSLong Integer1
HH MMLong Integer2
Hour Min SecLong Integer3
Hour MinLong Integer4
HH MM AM PMLong Integer5

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"

See Also

Date, Num, Time string.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next