Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11822

Re: Escape character for single quotes. Is it really required in String?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Knute Johnson <nospam@knutejohnson.com>
Newsgroups comp.lang.java.programmer
Subject Re: Escape character for single quotes. Is it really required in String?
Date Tue, 07 Feb 2012 10:28:36 -0800
Organization A noiseless patient Spider
Lines 41
Message-ID <jgrqgk$sf1$2@dont-email.me> (permalink)
References <93e3af31-e4d8-43df-9c03-9645b6885d1e@l16g2000vbl.googlegroups.com> <BoednbdHwOXVlqzSnZ2dnUVZ8kudnZ2d@giganews.com> <2362811.69.1328617748528.JavaMail.geo-discussion-forums@pbcjq2>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 7 Feb 2012 18:28:37 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="29153"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6PMuxYrj79O14kbl7AUwP"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:10.0) Gecko/20120129 Thunderbird/10.0
In-Reply-To <2362811.69.1328617748528.JavaMail.geo-discussion-forums@pbcjq2>
Cancel-Lock sha1:MKY9VK617hbgS7dcCjGe74WUG0o=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11822

Show key headers only | View raw


On 2/7/2012 4:29 AM, Mausam wrote:
> On Tuesday, 7 February 2012 17:00:16 UTC+5:30, Leif Roar Moldskred  wrote:
>> Mausam<mausamhere@gmail.com>  wrote:
>>
>>> How the two string is different? And when should I use escape
>>> character for single quote?
>>
>> In character literals.
>>
>>    char apostrophe = '\'';
>
> Thanks. For char it makes sense. But then my understanding that this escape character does not make any difference when used in String is correct.
>
>
>>
>> --
>> Leif Roar Moldskred
>

and the Strings are equal;

public class Class1 {

     private static String str = "I have a single quote. That's it";
     private static String str1 = "I have a single quote. That\'s it";
     public static void main(String[] args) {
         System.out.println(str);
         System.out.println(str1);
         System.out.println(str.equals(str1));
     }
}


C:\Documents and Settings\Knute Johnson>java Class1
I have a single quote. That's it
I have a single quote. That's it
true

-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Escape character for single quotes. Is it really required in String? Mausam <mausamhere@gmail.com> - 2012-02-07 03:14 -0800
  Re: Escape character for single quotes. Is it really required in String? Mausam <mausamhere@gmail.com> - 2012-02-07 03:18 -0800
  Re: Escape character for single quotes. Is it really required in String? Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-02-07 05:30 -0600
    Re: Escape character for single quotes. Is it really required in String? Mausam <mausamhere@gmail.com> - 2012-02-07 04:29 -0800
      Re: Escape character for single quotes. Is it really required in String? Knute Johnson <nospam@knutejohnson.com> - 2012-02-07 10:28 -0800
  Re: Escape character for single quotes. Is it really required in String? Lew <lewbloch@gmail.com> - 2012-02-07 11:11 -0800

csiph-web