Copy link to clipboard
Copied
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;
}
- Sudha K
Have something to add?