1 Reply Latest reply on Jul 17, 2008 1:13 PM by 843785

    String positions in a long string


      Iam sure some of you have encountered this problem. I have a long String, when i mark a word in a the string, i want to get the start and end positions of the marked word.

      I did it with this code:
      String article = "An example of the long string, the string could be an article, book etc..";
                               //getSelectedText returns the marked string
                     String temp = mainPanel.getCenterPanel().getMarkArea().getSelectedText();
                     System.out.println("Text: "+temp);
                     System.out.println("start pos: " + article.indexOf(temp));
                     System.out.println("End pos: " + (article.indexOf(temp)+temp.length()));
      This works, however if the word occures more than once, it will allways return the first char pos start, end of the marked word. How can I make it so it will return the char pos start and end of the "marked" word? Is there any usefull methods that I can use?