This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Putting escape characters into a string  RSS feed

 
Chris Hembel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem with this code in a class file I am building. This is the code I have in my Class file:


When I compile the file, I get this error:


^

What I don't understand is that I thought I was using the correct character combination to make the single quote in the string. If I don't use the escape character, when I call the method in the driver class that I use I get a weird character for the single quote. This is what it looks like in the display:

LetÆs take you to a verse

But if I try to use \' I get the error. I don't know what I am doing wrong.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

You don't need to escape the quote. It looks like you are using a non-English quote character though. Yours tilts toward the left. When I type a quote it goes straight down.
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Jeanne points out, your single-quotation-mark symbol looks wrong. I think you are using the right single quotation mark versus an apostrophe. Only the apostrophe can be escaped. On my Linux system your code (without the \) prints OK, but does show a right single quotation mark.

If your keyboard can't generate an apostrophe you can get it by:

char ch = (char) 39;

The character you are showing appears to be

char ch = (char) 8217;

 
Campbell Ritchie
Marshal
Posts: 55715
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For posh quotes try \u201c \u201d \u2018 and \u2019
 
Chris Hembel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much.

It is my laptop keyboard that does that. When I look really close I can see that the symbol is really a right quote instead of an apostrophe. I put the file on my desktop, replaced the character with my standard keyboard and TADA! it worked.

Chris
 
Campbell Ritchie
Marshal
Posts: 55715
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done. You realise you can change the keyboard preferences and select a kayboard ↦ characters mapping which will preserve '’‘, etc?
 
Chris Hembel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do now.

I will be changing my laptop as that is the machine I use to work on this stuff.

Chris
 
Campbell Ritchie
Marshal
Posts: 55715
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look here (try 103P) and here.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!