• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

how to print "" as string

 
Ranch Hand
Posts: 94
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
How to print this "" as output?


Is it possible?
Thank You
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know how to print a single double-quote character?

The solution is that you have to escape certain "special characters" - the quote is one. so inside a pair of quote, you use a back-slash to tell Java (and many other languages) "treat the next character different than normal".

So a single double-quote character could be printed like this:



Now try and extend that to print two double quotes.
 
Marshal
Posts: 80096
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

To continue from what Fred told you, the Java® Tutorials and the Java® Language Specification (=JLS) have lists of escape sequences. I think you should avoid octal escapes; use Unicode instead.
I think you can put single quotes ' in String literals and double quotes " in char literals without escapes.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unicode escapes are not going to work for this. Unicode escapes are processed before the code is parsed, so writing quotes using Unicode escapes is exactly the same as writing the quotes directly, as far as the compiler is concerned.
 
Campbell Ritchie
Marshal
Posts: 80096
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant to say use Unicode instead of octal. But you are quite right, Jesper, that you cannot use Unicode escapes instead of \' \" \b \f \n \r \t or \\.

[edit]Add “say”[/edit]
 
Saloon Keeper
Posts: 28402
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Yes, I know "println" does an OS-independent newline, but I'm grandstanding here.

Most languages handle syntactical ambiguities in one of 2 ways, there either double-up or they use an escape character.

SQL and BASIC double up : 'O''Brian'.

C/C++/Java/Perl and others use an escape character 'O\'Brian'. Raw character codes are generally an option, too. Usually an escaped escape character doubles up, but I think if I tried I could come up with a language or 2 that did that trick differently.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Define a character in unicode to denote the expression and then use it within context in your println command.

i.e.

 
Campbell Ritchie
Marshal
Posts: 80096
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is \u0093 supposed to mean? It is not a printing character.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic