Syntax 2 For blobs
Description
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.
Syntax
1 |
<span>String</span> ( <span>blob</span> {,<span>encoding</span>} ) |
Argument |
Description |
---|---|
blob |
The blob whose value you want returned |
encoding |
Character encoding of the blob you want
|
Return Values
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.
Usage
If the encoding argument is not provided, String converts
a Unicode blob to a Unicode string. You must provide the encoding argument
if the blob has a different encoding.
If the blob has a byte-order mark (BOM), String filters
it out automatically. For example, suppose the blob’s hexadecimal
display is: FF FE 54 00 68 00 69 00 73 00
.
The BOM is FF FE, which indicates that the blob has UTF-16LE encoding,
and is filtered out. The string returned is “This”.
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.
Examples
This example converts the blob instance variable ib_sblob,
which contains string data in ANSI format, to a string and stores
the result in sstr:
1 |
string sstr |
1 |
sstr = <span>String</span>(ib_sblob, EncodingANSI!) |
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:
1 |
blob{100} bb |
1 |
long pos1, pos2 |
1 |
string test_status |
1 |
date test_date |
1 |
1 |
test_date = Today() |
1 |
IF DayName(test_date) = "Wednesday" THEN & |
1 |
test_status = "Coolant Test" |
1 |
IF DayName(test_date) = "Thursday" THEN & |
1 |
test_status = "Emissions Test" |
1 |
1 |
// Store data in the blob |
1 |
pos1 = BlobEdit( bb, 1, test_date) |
1 |
pos2 = BlobEdit( bb, pos1, test_status ) |
1 |
1 |
... // Some processing |
1 |
1 |
// Extract the status stored in bb and display it |
1 |
sle_status.text = <span>String</span>( & |
1 |
BlobMid(bb, pos1, pos2 - pos1)) |
See Also
-
String method for DataWindows
in the DataWindow Reference or online Help