Class: String
Description
This method translates the character string into a byte string.
This method is equivalent to {ByteString}STR. The use of the toByteString method enhances readability, especially if a ByteString method needs to be applied to the result.
|
Please be aware that if you combine the toByteString method with other methods, then all methods to the right of the toByteString method refer to ByteString methods, not to String methods. |
Syntax
StringObject.toByteString()
Parameters
none |
|
Returns
The ByteString that represents the String in Runtime.charsetName.
When Became Available
Profile V7.0
Example
type String STR ="Knäckebröd"
// type cast and toByteString() are identical:
type ByteString BST1 = {ByteString}STR
type ByteString BST2 = STR.toByteString()
// in combination with additional methods toByteString enhances readability
type Number BYTELEN1 = ({ByteString}STR).length()
type Number BYTELEN2 = STR.toByteString().length()
// potential screw-up:
// - .extract() = ByteString.extract()
// - .length() = String.length() = 10 characters
// Result: 164.byte() _ "ckebr" _ 195.byte()
type ByteString BS = STR.toByteString().extract( 4, STR.length())