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

How to get the word after searching for a character with Javascript?

Engaged ,
Sep 20, 2022 Sep 20, 2022

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);
TOPICS
Scripting
574
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

correct answers 1 Correct answer

People's Champ , Sep 20, 2022 Sep 20, 2022
//Just climb up the object hierarchy
myFoundItems[0].words[0].contents;

 

But you may as well consider using GREP for a one-time go.

Translate
People's Champ ,
Sep 20, 2022 Sep 20, 2022
//Just climb up the object hierarchy
myFoundItems[0].words[0].contents;

 

But you may as well consider using GREP for a one-time go.

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
Engaged ,
Sep 20, 2022 Sep 20, 2022

Thank you very much for the quick tip.

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
Engaged ,
Sep 20, 2022 Sep 20, 2022
LATEST

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+

 

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