TextField and getCharBounds

For some strange reason, I can’t get to read the positions of the last character in my textfield. Here’s the code:

var textBox:TextField = new TextField();
var counter:Number = 0;
var rectangle:Rectangle;

var s:String = "Lorem ipsum dolor sit amet ";
textBox.width = 100;
textBox.wordWrap = true;
textBox.multiline = true;
textBox.autoSize = 'left';

textBox.text = s;

for (var i:Number=0; i<textBox.numLines; i++) {
    if (i>0) {
    var line:String = textBox.getLineText(i);
    counter+=line.length-1; //adds the length of current line for further matching in the whole text string

    if (counter<s.length-1) {
        rectangle = (textBox.getCharBoundaries(counter));
    } else {
        trace("last character of the text")
        trace (textBox.getCharBoundaries(counter)) // returns null why?
    trace(i +1+"° "+line.length.toString()+" "+counter.toString()+" "+s.charAt(counter));

function createRect(r:Rectangle) {
    var s:Shape = new Shape();
    s.graphics.drawRect(r.x, r.y, r.width, r.height);

edit: I found out that for an even stranger reason this code won’t work if the wrapped lines are more than 9. In fact the above code works, but if you keep adding lines to the string it will eventually stop when the lines are 10 or more.