Text selection is not giving the exact position : I have a text which is like ->

    **Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.**

Now, I want to highlight some part of this text . So, I need to know the start and end offsets of the string. 

Let's say 

    it to make a 
This text I want to highlight so, I need to have the offset of this text. So, for this I am using following logic 

    var startoffset  = $scope.original_doc_content.indexOf("it to make a ");
    var endoffset =  startoffset + string.length;


So, Now what is happening here is 
 if `it to make a` is present 2 times in a given text then if I want to highlight or want to take the second one and if it present before the 2nd one then it gives me the 1st ones offset and not the second one which I require. So,How can I resolve this ?