RAD function: substrb

A RAD function that extracts a substring from a multibyte character or binary string.

Function

substrb

Format

substrb(string, beginning position, length)

Parameters

The following parameters are valid for the substr function:

Parameter Data type Description
string String The string being modified.
beginning position Number The position in the string where the substring is to begin.
length Number

The total number of bytes you want the substring to contain. The default behavior is to include all remaining bytes in the string from the starting position. You can use the length parameter to specify a shorter byte length.

Caution You should choose a length value that takes into account the number of bytes available in the source string. If you choose too low a value the substituted string may contain corrupted data because the function did not have enough bytes to substitute a multibyte character. Refer to a UTF-8 or UTF-16 character encoding map to see how many bytes a particular multibyte character requires. It is recommended that you only use this function on strings of a fixed byte length to avoid possible data corruption. If you want to replace a fixed number of characters use the substr function instead.

Example

$a=substrb("abcÄÖÜdef", 5)
$b=substrb("abcÄÖÜdef", 1, 7)

After execution, the value of $a is ÖÜdef and the value of $b is abcÄÖ.

For the string $b, setting the length value to 4 or 6 would lead to data corruption because there are not enough bytes available to contain the multi-byte characters Ä and Ö respectively.