You are using "LineText[InitPos]" => which accesses bytes and not utf8-chars. (actually: codepoints)
Utf8Lenght returns the length in utf8-chars, not bytes. The Utf8Lenght may be less than the byte "Lenght()" of the string. You need to work with the byte length.
Since space (#32) is a single byte, accessing bytes is fine for that. So it would be for tabs #9. But not for other Unicode white spaces, such as half or zero width space, none breaking space and others. (Well byte access still works, and is preferred, but needs a bit more work for such white spaces)
Not sure if you plan to deal with punctuation, and Unicode word-break codepoints? Or control codepoints in Unicode such as LTR,RTL,...
Further more, if you detect spaces and copy the text between (assuming you do that correctly), then you should not need "trim".