Type
| Function |
Description
| Extracts one character out of a string. 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 code (observe the following notes). |
Notes |
- If IN > 0 (string length > 0) and N <= IN, the function returns the ASCII 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).
|
Parameters
| Inputs
IN
Data type: | STRING |
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 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_CHAR( 'drive', 3 ); (* stores 105 (decimal value of character 'I') in var1 *)
|