I need a function to cut string to given appearance of another string. I tried to do it like that:
function substring2(inputText, limitText: String; max: Integer): String;
var
lastAppearence: Integer;
begin
lastAppearence := 0;
for var I := 0 to max - 1 do
begin
lastAppearence := inputText.IndexOf(limitText, lastAppearence + I);
if lastAppearence = -1 then
begin
lastAppearence := inputText.Length;
break
end;
end;
result := inputText.Substring(0, lastAppearence);
end;
I think there could be a way to do it simplier or better. Is there any function from basic Delphi Library, or maybe i could do it better some way?