Type
| Function |
Description
| Extracts one character out of a string of a variable of the data type WSTRING. The string from which the character is to be extracted is applied to the IN input. The number of the character to be extracted is specified at the N input. The output value represents the number of the character in ASCII 256 or UTF-8 code (observe the following notes). |
Notes |
- If IN > 0 (string length > 0) and N <= IN, the function returns the ASCII or UTF-8 code number of the extracted character.
- If the above condition is not true, the function returns the value 0 (see also the error behavior below).
- Characters represented by four bytes: Some characters have four bytes though but only the double byte at a 2-byte oriented position will be returned. Therefore the position of a specific character moves if four byte characters are part of the string.
|
Parameters
| Inputs
IN
Data type: | WSTRING |
Description: | Input string. |
N
Data type: | ANY_INT |
Description: | Number of the character within the string starting from the left. |
Output
OUT
Data type: | INT |
Description: | ASCII 256 or UTF-8 code number of the extracted character. |
|
Error behavior
| Error behavior
The following table shows the errors which may occur while executing the function and the value returned by the function in the corresponding error case.
Error case | Output value |
N <= 0 | 0 |
N > len(IN)(len(...) = actual string length) | 0 |
If any of the listed errors occurs or in case of a wrong input, the result variable is set to 0 and a string error occurs. Furthermore, the controller runtime logs the error in its error catalog. In online mode, a corresponding error message is shown in the Error List log in the MESSAGES window. The controller remains in RUN state.
Note
Controller stop on string error: The controller can be automatically stopped when a string error occurs. This allows you to locate the error in your project. To enable the automatic stop of the controller in case of a string error, activate the button in the Cockpit toolbar of the controller. |
|
Additional information
| EN/ENO behavior
The POU is only executed if TRUE is applied to the EN input. If EN = FALSE, the POU is not executed and ENO = FALSE indicates the inactivity.
If any of the errors listed under "Error behavior" occurs while executing the function, ENO is set to FALSE.
|
Example | Example in ST
var1 := GET_WCHAR( 'drive', 3 ); (* stores 105 (decimal value of character 'I') in var1 *)
|