Copy link to clipboard
Copied
Hello,
I want to search for a specific letter like "ñ" in InDesign using Javascript. findText is the fastest way than using indexOf.
But how can I then determine the word like "señior" in which the letter occurs?
.constructor.name tells me I have found a character.
.parent returns "story" as a result and not the word in which the character is contained.
How can I determine the word from the search result?
My (simplified) Javascript looks like this:
// Find a character and get the word
var myDocument = app.activeDocument;
app.findTextPreferences.findWhat = "ñ";
var myFoundItems = myDocument.findText();
alert(myFoundItems[0].constructor.name);
alert(myFoundItems[0].parent);
//Just climb up the object hierarchy
myFoundItems[0].words[0].contents;
But you may as well consider using GREP for a one-time go.
Copy link to clipboard
Copied
//Just climb up the object hierarchy
myFoundItems[0].words[0].contents;
But you may as well consider using GREP for a one-time go.
Copy link to clipboard
Copied
Thank you very much for the quick tip.
Copy link to clipboard
Copied
Hi,
As Loic said, I would have gone for a Grep query as well (which can be put into a script too)
something as simple as that
\b\w+ñ\w+