procedure TForm1.btn1Click(Sender: TObject);
var
SourceString, TempString: string;
StartIndex, EndIndex: Integer;
begin
SourceString := '55551234567891555';
StartIndex := Pos('1', SourceString);
TempString := Copy(SourceString, StartIndex + 1, MaxInt);
EndIndex := Pos('1', TempString);
TempString := Copy(SourceString, StartIndex + 1, EndIndex - 1);
TempString := StringReplace(SourceString , TempString, '22222222222222', [rfReplaceAll, rfIgnoreCase]);
edt1.Text := TempString;
end;