Is it possible to put qoutes marks inside a string?

Link To Project
What I expect to happen: the code to ignore the parenthesis in the string
What actually happens: it creates an error upon pressing run (ERROR: Line: 92: SyntaxError: Unexpected token (94:46)
)

@justinolsen2007

You didn’t share a link to your code, but if you do, we can take a look at it. I wouldn’t think a parenthesis inside a string would need to be escaped, but if you are able to share a link to the project, we could see if there is a way to see what is going on.

thanks,

Mike

i added it. I’m making a project where you press the keybind ~ click where you want the sprite ~ and it gives you back code in the console for it. (cords, sprite animation, sprite size, more in future). (edit: I btw removed them so your gonna need to add the parenthesis back to see the error, i can put them back where they were causing the error if you want.)

Did you figure it out? It looks like it is working to me …

Mike

No, i just removed the parentheises causing it. ill add them back

when i add them all the lines under it gets a alert “Unclosed String” and when ran the function under it will error with the error above

If you could put a comment line in your code where the parenthesis are that you are experiencing problems with, that could help. I must be looking at the wrong ones.

Mike

So, I think you are talking about adding quote marks (not parenthesis…). On line 92, correct?

Try this line:

console.log("SpriteName.setAnimation(\"" + (SpriteAnimationName + "\");"));

I used a \ to escape the " marks.

Mike

1 Like

oh opps… i got them mixed up…:frowning: i will try the new code

it worked! thank you :slight_smile:

1 Like

The code seems to be working… But yes, you need to place a \ character to place a string character in a string.

Instead of having a lot of escaping slashes, you can just place your double quotation marks inside of single quotations.

True… in this case, I found that almost as confusing, but you are right. If only we could do template literals. :wink:

Mike

It kind of depends on the programming language, but some common patterns are:

  • Special characters such as quote could be “escaped” by using the back slash \ before using the special character:

var str = "This is my \" quote character"; console.log(str); //javascript

you will see that the console displays the string correctly without adding the \ character

  • You could also define the string with single quotes, so that double quotes don’t need to be escaped:

var str = 'This is my " quote character'; console.log(str); //javascript

This should display the same.