Is there a function that converts the character offset in a multi line string to line and column index?

Is there a function that converts the character offset in a multi line string to line and column index?

Say I have a string s and a string list sl:

sl.Text := 'abc'#13#10'defgh'#13#10'i'#13#10'jklm';
s := sl.Text;

or as text:

abc
defgh
i
jklm

I have the offset of the character 'g' (=9) into that string but I want to get the index of the line containing that character in sl[] (=2) and the position of the character in that line (=4).

I would have expected TStringList to have a method for this, but I can't find it. Google also didn't help, probably I was unable to find the correct search terms for this.

I'm going to implement it myself now, but I am sure somebody else already has done so.

Comments