Copy link to clipboard
Copied
Seems simple, right? And yet this doesn't work (you can see the debugger showing that the contents are "NOTE"), even when I use the more-permissive "==" comparison:
Copy link to clipboard
Copied
Your paragraph also likely will have a return character \r in it too. Debug by inspecting currPara.contents with an extra quote around it. Be curious as to why behavior you would expect doesn't turn out to be true.
Copy link to clipboard
Copied
Thanks for the reply. Yes, I suspected that it included the return character, and proved that was true by printing the character count (5). But then I tried comparing the first word to the string, and that also failed. So it's not clear what entity will match a string in quotes.
A Web search on the issue turns up nothing but wrong examples.
Copy link to clipboard
Copied
It's not as simple as it seems! 🙂
InDesign text may contain and, in most cases, does contain special (hidden) characters like anchored objects, indexes, xrefs, etc.
To handle them effectively by script, I wrote a couple of functions and posted them here.
Copy link to clipboard
Copied
Thanks! Can't access that site, though. It times out.
Also, you'd think an API to a word-processing application would anticipate the need to compare strings. Especially if I ask for a word.
Copy link to clipboard
Copied
You can test a regular expression against the contents:
/note/gi.test(myPara.contents)
Copy link to clipboard
Copied
Thanks. That's probably the most reliable way.
How would one extract a substring by index (from a paragraph) and compare it to a string? I'm not sure at what point (if any) there's a plain JavaScript string to be had for a direct comparison.
Copy link to clipboard
Copied
Try == instead of ===
Copy link to clipboard
Copied
@Peter Kahrel He tried this and it didn't work: see the OP.
Copy link to clipboard
Copied
Oops
Copy link to clipboard
Copied
Ha ha, NP; it's not totally obvious how many = there are with some fonts.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now