12 Replies Latest reply on Jan 6, 2011 8:42 AM by pkrk

    Dealing with Special Characters.

    pkrk Level 1

      What is the syntax to check if a character is a certain special character?

       

      ...if(myCharacter.contents!=SpecialCharacters.INDENT_HERE_TAB)

      {

      .

      .

      .

      }

        • 1. Re: Dealing with Special Characters.
          Peter Kahrel Adobe Community Professional & MVP

          If you try that, you'll find that the answer is "Yes".

          indentHereTab works, too.

           

          Peter

          1 person found this helpful
          • 2. Re: Dealing with Special Characters.
            Harbs. Level 6

            That should work (although you'd want the == operator if your are testing for its existence...)

             

            Harbs

            • 3. Re: Dealing with Special Characters.
              Harbs. Level 6

              Peter got there first...

               

              Harbs

              • 4. Re: Dealing with Special Characters.
                pkrk Level 1

                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?

                • 5. Re: Dealing with Special Characters.
                  pkrk Level 1

                  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

                  • 6. Re: Dealing with Special Characters.
                    Harbs. Level 6

                    end of paragraph is "\r".

                     

                    Harbs

                    • 7. Re: Dealing with Special Characters.
                      pkrk Level 1

                      I should have realized that .. thank you!

                      • 8. Re: Dealing with Special Characters.
                        Marc Autret Level 4

                        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

                        1 person found this helpful
                        • 9. Re: Dealing with Special Characters.
                          Harbs. Level 6

                          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

                          • 10. Re: Dealing with Special Characters.
                            Marc Autret Level 4

                            That's right, Harbs. My post was just a passing remark. I had so many problems with special characters when I started scripting, I just wanted to share.

                             

                            @+

                            Marc

                            • 11. Re: Dealing with Special Characters.
                              Harbs. Level 6

                              Sure thing. I just wanted to clarify the point for anyone who might be reading this...

                               

                              Harbs

                              • 12. Re: Dealing with Special Characters.
                                pkrk Level 1

                                Thanks guys - all the extra info is greatly appreciated!