use str_width() for the line breaks. if you use str_length (which returns the number of characters) and you're working with true type fonts then lines will have different lengths on screen because an m is longer than an l, so 5 lllll will be much shorter than 5 mmmmmm. str_width will let you cut the line where you want it.
What you're trying to do will be quite some work. I wrote my chat with a scrolling text struct which consists of Text objects (one per line) so that I can color ever line a different color (in case multiple people chat). The line break is a pain as well, because usually text fields don't break after a set width but after the last word that fully fits into the line.
So I'd say use every shortcut you can.
The inchar function sounds very interesting though. i have no idea how you'd do the text selecting though...
Good luck. and use str_width.