Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Alternative quote characters?

  Asked By: Thelma    Date: Apr 21    Category: Java    Views: 841

Can anyone tell me if there is a way of specifying alternative
characters to use as the quote character? I am reading in a string
which may already have both double and single quotes in it, so I am
wanting to temporarily designate another character to use to wrap the
string to I don't prematurely terminate the string.

I know it can be done in Perl by using qq![string text here]! which
in this case will enable the bang to be treated as a quote (any
character can be used here, not just a bang, so you would pick one
that you knew wouldn't be in the string. How do I do something
similar in Java.



1 Answer Found

Answer #1    Answered By: Wilbert Patterson     Answered On: Apr 21

Speaking of languages with alternative  means of specifying quotes, C# has a
lovely one. For instance, let's say I want to make a multiline string  with
quotes in Java:

String js = "\n<script language=\"JavaScript\">\n\talert(\"Hi!\");\n</script>";

I could do it in C# like this:

string js = @"
<script language=""JavaScript"">

Now why can't Java have something like that?

Didn't find what you were looking for? Find more on Alternative quote characters? Or get search suggestion and latest updates.