The function SetSel should be able to move the caret to desired location, but you have to provide correct arguments. Other useful functions are LineIndex and
ReplaceSel.
Maybe you parse the input string incorrectly, or the existing lines are too short? Show some details about your attempts.