Text.InsStr(Text, Text, Integer) Method

Version: Available or changed with runtime version 1.0.

Inserts a substring into a string.

Syntax

NewString :=   Text.InsStr(String: Text, SubString: Text, Position: Integer)

Note

This method can be invoked without specifying the data type name.

Parameters

String
 Type: Text
The string into which you want to insert a substring.

SubString
 Type: Text
The substring that you want to insert into String.

Position
 Type: Integer
Specifies where to insert SubString. Position must be greater than or equal to 1. If Position is greater than the length of String, then the result is concatenated and copied to NewString.

Return Value

NewString
 Type: Text
The input string including the specified substring

Remarks

If SubString is empty, then String is returned unchanged.

If Position is less than 1, an error is returned.

If Position is greater than the length of String, SubString is added at the end of String. For example, InsStr("Thomas","AAA",999) returns 'ThomasAAA'.

Example

var
    Str: Text[60];  
    SubString: Text[60];  
    NewString: Text[60]; 
    Text000: Label 'Press ENTER to continue.';  
    Text001: Label 'or ESC';
    Text002: Label ' The test string before InsStr is called:>%1<';
    Text003: Label ' The resulting string after InsStr is called:>%1<'; 
begin
    Str := Text000;  
    SubString := Text001;  
    Message(Text002, Str);  
    NewString := InsStr(Str, SubString, 13);  
    Message(Text003, NewString);  
end;

The first message window displays the following:

The test string before InsStr is called:

>Press ENTER to continue.<

The second message window displays the following:

The resulting string after InsStr is called:

>Press ENTER or ESC to continue.<

Text Data Type
Get Started with AL
Developing Extensions