What is the syntax to check if a character is a certain special character?
...if(myCharacter.contents!=SpecialCharacters.INDENT_HERE_TAB)
{
.
.
.
}
I was just returning to say I figured it out but why does the Object Reference show the values all caps and with underscores SpecialCharacters.COLUMN_BREAK, instead of what it is, SpecialCharacters.columnBreak?
Should I have been looking somewhere else for that value or is there some rule i don't know about?
Thanks for your help ... did you guys happen to check out my other question about Graphics from yesterday?
Is there another way to reference the value of SpecialCharacters?
When I do the same thing for paragraphSymbol it doesn't recognize it.It is working for other special characters though.
When I loop through the characters and send out an alert to see what is being read byt the script, when it gets to the end of the paragraph it spits out a "blank" for the contents and actually does a hard return and give me a false when I'm expecting a true?
alert(myCharacter.contents+" " +(myCharacter.contents==SpecialCharacters.paragraphSymbol).toString() );
Thanks
1) Also, it's important to remember that any SpecialCharacters member is implemented as a pure Number:
'number' == typeof SpecialCharacters.INDENT_HERE_TAB; // true
And, in this case:
1397319796===SpecialCharacters.INDENT_HERE_TAB; // true
So there is a potential issue in just using == or != when dealing with text contents. Suppose that a textual object (story, textframe, line, word, etc.) contains the string "1397319796". Then the test:
myText.contents == SpecialCharacters.INDENT_HERE_TAB;
will return true, which is not exactly what you expected! Indeed, JavaScript considers that:
"1397319796" == 1397319796;
So, when you compare a contents property and a SpecialCharacters member, it's recommended to use a triple-equal sign (===), or the opposite !==, to prevent any surprising conclusion.
// Here we are sure that .contents is an actual IndentHereTab
myText.contents === SpecialCharacters.INDENT_HERE_TAB;
(Note that myText.contents, here, is a Number, not a String.)
2) Another dangerous issue is that every SpecialCharacters member is silently converted into a String object (a simple character) when myText.contents contains *other* characters. For example, if myStory contains "A" followed by an IndentHereTab, then myStory.contents returns a string of two characters:
myStory.contents === "A\x07";
because SpecialCharacters.INDENT_HERE_TAB is internally translated into U+0007.
But of course, you still have:
myStory.characters[1].contents === 1397319796; // true
and not:
myStory.characters[1].contents === "\x07"; // false
myStory.characters[1].contents == "\x07"; // false
See also:
http://www.indiscripts.com/post/2009/07/idcs4-special-characters
@+
Marc
Hey Marc,
While what you say is technically true, I don't think that this case is really a problem. If you are testing for a special character, the test has to be done on a single Character (or it'll fail for sure!) which can't contain more than a single character, so the test can't really fail for the reasons you say... ![]()
Harbs
North America
Europe, Middle East and Africa
Asia Pacific