MID

Copy characters from a middle position

MID copies L characters of the string IN starting at position P with 1 denoting the first character of the string. The result is written into the output variable.

Parameters

Input

IN (STRING)

Input string

L (INT)

Number of input string's characters that are copied

P (INT)

Start position of the input string to be copied, where 1 is the first character of the string

Output

Unnamed output (STRING)

Copied string

Remarks

  • If this instruction is used with UTF-8 strings, please refer to the notes concerning UTF-8 strings under the data type STRING.

  • The sum of start position and number of characters to be delivered should not be greater than the input string. If you want to receive for example 5 characters of a 10-character string, starting from position 7, only the last 4 characters are delivered.

  • If the output string is longer than the length defined for the output variable in the field [Type], only as many characters are copied as the output variable can hold.The system variable sys_bIsCarry is set.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)

if a string applied at the input or output is an invalid string

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)

if a string applied at the input or output is an invalid string

sys_bIsCarry (turns to TRUE for one scan)

if the output string is longer than the length defined for the output variable in the field "Type"

POU 헤더

이 펑션 프로그램 시 사용한 모든 입력과 출력 변수는 POU 헤더에서 선언되었습니다. 모든 프로그래밍 언어에 같은 POU 헤더를 사용합니다.

	VAR
		sInputString: STRING[32]:='A better life. A better world.';
			(*sample string*)
		iNumberOfCharacters: INT:=15;
			(*characters to be delivered*)
		iStartPos: INT:=16;
			(*position to start copying*)
		sResultString: STRING[15]:='';
			(*result here: 'A better world.'*)
	END_VAR

이 예에서 입력 변수(sInputString, iNumberOfCharactersiStartPos)가 선언됩니다. 대신 문자열, 전달할 문자 수 및 펑션에서 직접 시작하는 위치를 입력할 수 있습니다. POU 헤더와 펑션 모두에서 문자열은 따옴표 안에 있을 수 있습니다.

POU 본문

iStartPos(16)부터 시작하는 sInputStringiNumberOfCharacters(15)는 sResultString에 복사됩니다.

LD 본문

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,MID!,,22,0,27,5,,?DIN?DL?DP?C);
B(B_VARIN,,sInputString,20,1,22,3,);
B(B_VARIN,,iNumberOfCharacters,20,2,22,4,);
B(B_VARIN,,iStartPos,20,3,22,5,);
B(B_VAROUT,,sResultString,27,1,29,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST 본문

sResultString:=MID(IN:=sInputString, L:=iNumberOfCharacters, P:=iStartPos);

IL 본문

최종 수정일: 2024-02-26이 페이지에 대한 피드백Panasonic 직통 전화