StringReplaceFirst has similar functionality to StringReplaceAll, except that StringReplaceFirst replaces the first occurrence only of OldPattern with NewPattern in S string.

OldPattern can be one or more characters.

NewPattern can be one or more characters, or it can be blank, which effectively removes the first occurrence of OldPattern.

StringReplaceFirst is not sensitive to case - A is read as the same as a.

Also review StringReplaceAll.

Declaration: Function StringReplaceFirst( const S, OldPattern, NewPattern : string) : string;

A few examples.

procedure OnMapEvent(var Value:Variant);
var
Str1, Str2, Str3, Str4 : string;
begin
Str1 := '[Topic]Rhubarb [Topic]Lizards [Topic]Yurts [Topic]Permaculture'
 
//Returns 'abc|def#g'
Str2 := StringReplaceFirst('abc#def#g','#','|');
LogInfo(Str2);
 
//Returns '[Follow The Topics - Topic]Rhubarb [Topic]Lizards [Topic]Yurts [Topic]Permaculture'
Str3 := StringReplaceFirst(Str1,'topic','Follow The Topics - Topic');
LogInfo(Str3);
 
//Returns '12345678901234567890'
Str4 := StringReplaceFirst('012345678901234567890','0','');
LogInfo(Str4);
 
end;