version 2004.5 (Modified)
String (expression{; format}) String
Parameter | Type | Description | |
expression | Expression for which to return the string form | ||
(can be Real, Integer, Long Integer, Date, or Time) | |||
format | String | Number | Display format | |
Function result | String | String 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:
Example | Result |
String(2^15) ` Use default format | 32768 (Default format used here) |
String(2^15;"###,##0 Inhabitants") | 32,768 Inhabitants |
String(1/3;"##0.00000") | 0.33333 |
String(1/3) ` Use default format | 0.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 |
7 | MM/DD/YYYY Forced | 12/29/1996 |
8 | ISO Date Time | 1996-06-12T00:00:00 |
4D provides the following predefined constants:
Constant | Type | Value |
Short | Long Integer | 1 |
Abbreviated | Long Integer | 2 |
Long | Long Integer | 3 |
MM DD YYYY | Long Integer | 4 |
Month Date Year | Long Integer | 5 |
Abbr Month Date | Long Integer | 6 |
MM DD YYYY Forced | Long Integer | 7 |
ISO Date Time | Long Integer | 8 |
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:
Constant | Type | Value |
HH MM SS | Long Integer | 1 |
HH MM | Long Integer | 2 |
Hour Min Sec | Long Integer | 3 |
Hour Min | Long Integer | 4 |
HH MM AM PM | Long Integer | 5 |
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.