3 Replies Latest reply on Sep 27, 2012 12:48 AM by Bill joy

    Unterminated String constant

    Bill joy Level 1

      Hi All

      I am writing a JS script and call it using doScript() method.

      CString  script,cStr;

      cStr contain some text like :

       

      "I am new scrpit developer.

      I am not know how develop indesign script?

      but forums help me to develop my script."

       

      Now  add this cStr in script like this :

       

      script="#target indesign";

      script+="\n";

      script+="var myDocument = app.documents.add();\n";

      script+="var myTextFrame = myDocument.pages.item(0).textFrames.add();\n";

      script+="myTextFrame.geometricBounds = [\"5p\", \"5p\", \"80p\", \"80p\"];\n";

      script+="myTextFrame.contents =\"";

      script+=cStr;

      script+="\";";

       

      Now my Final Script in ExtendScript Toolkit is

       

      #target indesign

      var myDocument = app.documents.add();

      var myTextFrame = myDocument.pages.item(0).textFrames.add();

      myTextFrame.geometricBounds = ["5p", "5p", "80p", "80p"];

      myTextFrame.contents ="I am new scrpit developer.

      I am not know how develop indesign script?

      but forums help me to develop my script.";

       

       

      It give error Unterminated String Constant

       

      This is because whole text is not in single line.When i write this text in single line it run sucessfully.

      How pass this type of string in Script that script run sucessfully.

       

      Thanks

        • 1. Re: Unterminated String constant
          Mac_06 Level 2

          But it's working fine for me.

           

          Try below:

          var cStr = "I am new scrpit developer.I am not know how develop indesign script? but forums help me to develop my script"
          script="#target indesign";
          script+="\n";
          script+="var myDocument = app.documents.add();\n";
          script+="var myTextFrame = myDocument.pages.item(0).textFrames.add();\n";
          script+="myTextFrame.geometricBounds = [\"5p\", \"5p\", \"10p\", \"10p\"];\n";
          script+="myTextFrame.contents =\"";
          script+=cStr;
          script+="\";";
          app.doScript(script, ScriptLanguage.javascript);
          • 2. Re: Unterminated String constant
            -hans- Level 4

            hi,

             

            you've got to mask the linebreaks in the cStr. -> \\n or \\r

             

             

            
            var cStr = "I am new scrpit developer.\\rI am not know how develop indesign script? \\nbut forums help me to develop my script"
            
            
            

             

            But this also depends to the way you create the string, so there may be another appoach ...

             

            Hans-Gerd Claßen

            • 3. Re: Unterminated String constant
              Bill joy Level 1

              Thanks for Reply

               

              I know the Problem,  I already told you in my above post

              This is because whole text is not in single line.When i write this text in single line it run sucessfully.

               

              Problem is that, I am getting CString cStr text from another file and I want to write as it as i get it in cStr.  I do not want to change any thing in cStr  text.

              Is it possible  without changing in the text to write it?

               

              Thanks.