0 Replies Latest reply on Feb 1, 2017 6:43 PM by Sudha K

    Next Character

    Sudha K Level 1

      Hi,

       

           I have the selection(page number alone from 151f).  I need to select the next character "f" (Screenshot). Both are tagged separately. So there is some xml characters (ie., tags) in between page number (151) and the next character (f).

       

      If the next character is alphabets then the selection should be page number with alphabets.  Otherwise selection should be page number alone. I am using the below code but its throwing error.  How to define the breakFlg to break the loop when next character of alphabets is not found.

       

       

      Code:

       

      var sel = app.selection[0];

      var nextChar = getNextChar(sel)

      sel.select();

      //nextChar.select(SelectionOptions.addTo);

      alert("nxtChar " +nextChar.contents)

       

       

       

      function getNextChar(sel)

      {

          var resChar = null;   

          var breakFlg = 5;

          var brk = 0;

         

          var nxtChar = sel.texts[0].characters.nextItem(sel.texts[0].characters[sel.texts[0].characters.length-1 ]);   

          alert(nxtChar.contents + "\n "+(nxtChar.contents.match(/[a-zA-Z]/gi) ))

         

         

          while(nxtChar != null && nxtChar.contents.match(/[a-zA-Z]/gi) == null)

          {

              nxtChar = nxtChar.characters.nextItem(nxtChar);

              if(nxtChar != null)

              {

                  nxtChar.select()

                  alert("nxtChar " +nxtChar.contents)

              }

              if((brk > breakFlg) || (nxtChar.contents == "," || nxtChar.contents == "\r" || nxtChar.contents == "–"))

              {

                  break;

              }

              brk++;

          }

       

         

          return nxtChar;

      }

      nextChar.png

       

       

      error.png

       

       

      - Sudha K