# Extract String (Left/Right)

Extracts a string from the left or right edge.

##### Block

##### Text

TARGET = substringFromLeft(INPUT, COUNT);
1 2 4 3

# | Description
1 | [Destination Data] Set the destination where you want to store the extracted string.
2 | Direction to extract the string ##### Block [FromLeft] [FromRight] ##### Text 'substringFromLeft' 'substringFromRight' Select the direction used for extracting the string. (Example) String: "ABCDE", [Number of characters]: 3 Red characters are extracted. When [FromLeft] is selected: ABC DE When [FromRight] is selected: AB CDE
3 | [Number of characters] Set a block that specifies the number of characters to extract. The value must be greater than or equal to 1, and less than or equal to the number of characters that can be extracted. Double-byte characters are counted as a single character.
4 | [Source Data] Set the source data where the string to extract is stored.

(Example)

##### Block

##### Text

Var4 = substringFromLeft(Var3,Var1);

## Operation Example

Variable in [Source Data] | [Way to extract] | [Number of characters] | Variable in [Destination Data] | Comments
Target string | Maximum Number of Bytes | Extracted string to store
ABCDE | FromLeft | 3 | 5 | ABC | -
0 | 5 | (none) | A string is not stored because the [Number of characters] is less than 1. It is judged as fail in the "Operation Result" Operation.
3.6 | 5 | ABC | Values to the right of the decimal point in [Number of characters] are dropped.
FromRight | 3 | 5 | CDE | -
-1 | 5 | (none) | A string is not stored because the [Number of characters] is less than 1. It is judged as fail in the "Operation Result" Operation.
3.7 | 5 | CDE | Values to the right of the decimal point in [Number of characters] are dropped.
AB | FromLeft | 3 | 5 | (none) | A string is not stored because the [Number of characters] exceeds the number of retrievable characters. It is judged as fail in the "Operation Result" Operation.
FromRight | 3 | 5 | (none) | A string is not stored because the [Number of characters] exceeds the number of retrievable characters. It is judged as fail in the "Operation Result" Operation.
ABCD(0x00)C | FromRight | 3 | 5 | BCD | If there is a NULL (0x00), the string is terminated there.
AB(0x00)CD | FromLeft | 3 | 5 | (none) | A string is not stored. If there is a NULL (0x00), the string is terminated there. As a result, the [Number of characters] exceeds the number of retrievable characters. It is judged as fail in the "Operation Result" Operation.
AB(0x00)CDEF | FromRight | 3 | 5 | (none) | A string is not stored. If there is a NULL (0x00), the string is terminated there. As a result, the [Number of characters] exceeds the number of retrievable characters. It is judged as fail in the "Operation Result" Operation.
ABCDEFGH | FromLeft | 6 | 5 | (none) | A string is not stored because the converted string has exceeded the maximum number of bytes that can be stored. It is judged as fail in the "Operation Result" Operation.
FromRight | 6 | 5 | (none) | A string is not stored because the converted string has exceeded the maximum number of bytes that can be stored. It is judged as fail in the "Operation Result" Operation.
AあB | FromLeft | 3 | 5 | AあB | String is stored based on the [Number of characters]. *1
FromRight | 2 | 5 | あB | String is stored based on the [Number of characters]. *1

*1 If the maximum number of bytes in the [Destination Data] variable is less than the size of the retrieved string, the operation will fail. The maximum number of bytes depends on the encoding of the [Destination Data] variable.