Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Next Character

Contributor ,
Feb 01, 2017 Feb 01, 2017

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

TOPICS
Scripting
205
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation