Skip to main content
Participating Frequently
January 30, 2012
Question

searching for consecutive characters set in different character styles

  • January 30, 2012
  • 1 reply
  • 2767 views

I need to find a space (with no Character Style attributed to it) followed by another space (with "Character Style A" attributed to it).

Since "Character Style A" refers to a Right-to-Left script, simply searching for two consecutive spaces does not work – ID does not find them, since they do not exist, so to speak. The problem is, however, that if you look at the text, the word with "Character Style A" is not separated by a space from its Left-to-Right context.

Is there any way to find such an occurrences with a script?

I'm using ID CS5 ME.

This topic has been closed for replies.

1 reply

கற_பன___Imagine_
Inspiring
January 30, 2012

Try this below js code.

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = "  ";

var myResults = app.findText();

for (var i=0; i<myResults.length; i++) {

    var myWord = myResults;

    if (myWord.characters[0].appliedCharacterStyle.name == "[None]") {

        if (myWord.characters[1].appliedCharacterStyle.name == "Character Style A") {

             // found that white spaces.

             myWord.select();

            }

        }

}

I hope this helps to you..

samar02Author
Participating Frequently
January 30, 2012

Thank you, Imagine. I tested it, but nothing happens.

A Debug tells me that "null" is no object ... I have no idea yet what this means, I am still learning.

I should have mentioned earlier that ideally, my search would work within a book document containing many files. (I tested the script within just one file, so this can't be the issue here.)

Thanks for any input.

samar02Author
Participating Frequently
January 30, 2012

You didn't understand Samar's problem.

The issue is not that there are two consecutive spaces. The problem is that there appear to be two consecutive spaces.

This is caused by the fact tht Samar has a right-to-left attribute applied to the second space. Imagine that x is an English character and y is an Arabic character. If you have xxx yyy xxx, if yyy and the space following it has right-to-left applied, the text will look like this: xxx  yyyxxx. Samar needs to move the location of the second space to its correct location.

Now a question for Samar:

Why are you using right-to-left direction instead of default? If the character direction is default, the Arabic will be right to left, but the spcae will be in the correct location.

Harbs


Harbs, thank you for the clarification.

Using right-to-left instead of default for Character Style A is crucial for parenthesis and other punctuation to appear correctly (otherwise chaos reigns).