String has two syntaxes.
To |
Use |
---|---|
Format data as a string according to a specified display format mask |
|
Convert a blob to a string |
Formats data, such as time or date values, according to a format mask. You can convert and format date, DateTime, numeric, and time data. You can also apply a display format to a string.
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. Data can also be an Any variable containing one of these datatypes. |
format (optional) |
A string whose value is the display masks you want to use to format the data. The masks consists of formatting information specific to the datatype of data. If data is type string, format is required. The format can consist of more than one mask, depending on the datatype of data. Each mask is separated by a semicolon. (For details on each datatype, see Usage). |
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, format is not a valid mask, or data is an incompatible datatype.
For date, DateTime, numeric, and time data, PocketBuilder uses the system’s default format 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:
Formats for date, DateTime, string, and time data can include one or two masks. The first mask is the format for the data; the second mask is the format for a null value.
Formats for numeric data can have up to four masks. A format with a single mask handles both positive and negative data. If there are additional masks, the first mask is for positive values, and the additional masks are for negative, zero, and null values.
To display additional characters as part of the mask for a decimal value, you must precede each character with a backslash. For example, to display a decimal number with two digits of precision preceded by four asterisks, you must type a backslash before each asterisk:
dec{2} amount string = ls_result amount = 123456.32 ls_result = string(amount,"\*\*\*\*0.00")
The resulting string is ****123456.32
.
For more information on specifying display formats, see the Users Guide. Note that, although a format can include color specifications, the colors are ignored when you use String in PowerScript. Colors appear only for display formats specified in the DataWindow painter.
If the display format does not match the datatype, PocketBuilder tries to apply the mask, which can produce unpredictable results.
Times and dates from a DataWindow control When you call GetItemTime or GetItemString as an argument for the String function and do not specify a display format, the value is formatted as a DateTime value. This statement returns a string like "2/26/03 00:00:00":
String(dw_1.GetItemTime(1, "start_date"))
When you use String to format a date and the month is displayed as text (for example, the display format includes "mmm"), the month is in the language of the runtime DLLs available when the application is run. If you have installed localized runtime files in the development environment or on a user’s machine, then on that machine, the month in the resulting string is in the language of the localized files.
For information about the localized runtime files, which are available in French, German, Italian, Spanish, Dutch, Danish, Norwegian, and Swedish, see the chapter on internationalization in Application Techniques.
You can also use String to extract a string from the Message object after calling TriggerEvent or PostEvent. For more information, see the TriggerEvent or PostEvent functions.
This statement applies a display format to a date
value and returns Jan 31, 2002
:
String(2002-01-31, "mmm dd, yyyy")
This example applies a format to the value in order_date and
sets date1 to 6-11-02
:
Date order_date = 2002-06-11
string date1
date1 = String(order_date,"m-d-yy")
This example includes a format for a null date
value so that when order_date is null, date1 is
set to none
:
Date order_date = 2002-06-11
string date1
SetNull(order_date)
date1 = String(order_date, "m-d-yy;'none'")
This statement applies a format to a DateTime value
and returns Jan 31, 2001 6 hrs and 8 min
:
String(DateTime(2001-01-31, 06:08:00), &
'mmm dd, yyyy h "hrs and" m "min"')
This example builds a DateTime value from the system
date and time using the Today and Now functions.
The String function applies formatting and sets
the text of sle_date to that value,
for example, 6-11-02 8:06 pm
:
DateTime sys_datetime
string datetime1
sys_datetime = DateTime(Today(), Now())
sle_date.text = String(sys_datetime, &
"m-d-yy h:mm am/pm;'none'")
This statement applies a format to a numeric value
and returns $5.00
:
String(5,"$#,##0.00")
The statements in the following table set the string variable string1:
PowerScript code |
Result |
---|---|
integer nbr = 123
string string1
string1 = String(nbr,"0000;(000);****;empty")
|
0123 |
integer nbr = -123
string string1
string1 = String(nbr,"000;(000);****;empty")
|
123 |
integer nbr = 0
string string1
string1 = String(nbr,"0000;(000);****;empty")
|
**** |
integer nbr
string string1
SetNull(nbr)
string1 = String(nbr,"0000;(000);****;empty")
|
“empty” |
The statements in the following table format string
data, assigning a characer in the source string to each @
and
inserting other characters in the format at the appropriate positions:
Statement |
Result |
---|---|
String("ABC", "@-@-@")
|
A-B-C |
String("ABC", "@*@")
|
A*B |
String("ABC", "@@@")
|
ABC |
String("ABC", " ")
|
blank space |
The statements in the following table apply display formats to time data:
Statement |
Result |
---|---|
String(06:08:02,'h "hrs and" m "min"')
|
6 hrs and 8 min |
String(20:06:04,"hh:mm:ss am/pm")
|
08:06:04 pm |
String(08:06:04,"h:mm:ss am/pm")
|
08:06:04 pm |
PocketBuilder allows you to use the String function to convert numeric data to hexadecimal formatting. The statements in the following table apply hexadecimal formatting to the decimal value 12:
Statement |
Result |
---|---|
String(12,"hex")
|
C |
String(12,"hex2")
|
0C |
String(12,"hex4")
|
000C |
String(12,"hex8")
|
0000000C |
String method for DataWindows in the DataWindow Reference
Converts data in a blob to a string value. If the blob’s value is not text data, String attempts to interpret the data as characters.
String ( blob )
Argument |
Description |
---|---|
blob |
The blob whose value you want returned as a string. Blob can also be an Any variable containing a blob. |
String. Returns the value of blob as a string if it succeeds and the empty string ("") if it fails. It the blob does not contain string data, String interprets the data as characters, if possible, and returns a string. If blob is null, String returns null.
You can also use String to extract a string from the Message object after calling TriggerEvent or PostEvent. For more information, see the TriggerEvent or PostEvent functions.
This example converts the blob instance variable ib_sblob, which contains string data, to a string and stores the result in sstr:
string sstr
sstr = String(ib_sblob)
This example stores today’s date and test status information in the blob bb. Pos1 and pos2 store the beginning and end of the status text in the blob. Finally, BlobMid extracts a "sub-blob" that String converts to a string. Sle_status displays the returned status text:
blob{100} bb
long pos1, pos2
string test_status
date test_date
test_date = Today()
IF DayName(test_date) = "Wednesday" THEN &
test_status = "Coolant Test"
IF DayName(test_date) = "Thursday" THEN &
test_status = "Emissions Test"
// Store data in the blob
pos1 = BlobEdit( bb, 1, test_date)
pos2 = BlobEdit( bb, pos1, test_status )
... // Some processing
// Extract the status stored in bb and display it
sle_status.text = String( &
BlobMid(bb, pos1, pos2 - pos1))
String method for DataWindows in the DataWindow Reference