SET_CHAR

Write a character value into the position of a string

This function sets the 8-bit character value of sString with iPosition denoting the position of the character in the string where 1 is the first character of the string.

Input

Value (WORD, DWORD)

The input data from which the lower byte value is written to the character data

iPosition (INT, DINT, UINT, UDINT)

Position of the character in the string, where 1 is the first character of the string, must be greater than or equal to 1

Input/output

sString (STRING)

String to which the character is set

Remarks

  • The position is assumed to be greater than or equal to 1.

  • Please check the validity of the input data since the validity of the data to access is not checked.

  • Please check that the specified position does not exceed the maximum number of characters or is higher than the current number of characters.

  • When you apply a SET_CHAR function to a string, the length of the string, i.e. the current number of characters in the string, is not changed. If it is necessary to change the length of the string, use the function SET_LEN.

NOTE

To get the best performance please use constant input values as much as possible!

Example

POU header

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

	VAR
		bStart: BOOL:=FALSE;
		sInputString: STRING[32]:='ABCDabcd';
	END_VAR

LD body

When the variable bStart is set to TRUE, the function is carried out.

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 8 ;
        NETWORK_BODY
B(B_CONTACT,,bStart,4,3,6,5,);
B(B_F,E_SET_CHAR!,,14,2,22,8,,?DEN?DValue?DiPosition?DsString?AsString?AENO);
B(B_VARIN,,77,12,4,14,6,);
B(B_VARIN,,8,12,5,14,7,);
B(B_VARIN,,sInputString,12,6,14,8,);
L(1,0,1,8);
L(1,4,4,4);
L(6,4,14,4);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if (bSTart) then
	SET_CHAR(Value := 77, iPosition := 8, sString := sInputString);
end_if;

Modified on: 2025-02-28Feedback on this pagePanasonic hotline