This site requires JavaScript, please enable it in your browser!
Greenfoot back
Barador
Barador wrote ...

2012/11/22

Automatic Quotation Marks

Barador Barador

2012/11/22

#
Hi If i have code like this:
xyz = Integer.toString(zyx);
Can I automatically add quotation marks at the beginning and at the end of the String. I tried it with:
xyz = """ + Integer.toString(zyx) + """;
but I think this is only possible if there is something else in the "" right?
danpost danpost

2012/11/22

#
Being that the quotation is signifies the beginning and the end of a string, you cannot just put one in the middle of a string and expect the compiler to know what you want. The easiest way to insert a quotation mark within a string is to preceed it with a backslash (using an escape sequence). So your statement above would be
xyz = "\"" + Integer.toString(zyx) + "\"";
You could also use
xyz = (char)34 + Integer.toString(zyx) + (char34);
Zamoht Zamoht

2012/11/22

#
I'm not sure at all, but try add the quotation marks as chars like: char qMark = '"'; xyz = "" + qMark + Integer.toString(zyx) + qMark;
Zamoht Zamoht

2012/11/22

#
Sorry danpost for posting almost the same answer as you, but the thread wasn't updated when I started writing. Okay maybe not the same answer...
You need to login to post a reply.