This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes small doubt  in escape sequences Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "small doubt  in escape sequences" Watch "small doubt  in escape sequences" New topic
Author

small doubt in escape sequences

Johnson David
Greenhorn

Joined: May 22, 2005
Posts: 27
My doubt is regarding backspace , /b

If i use /b in a string literal like the fallowing

String bs="this is my back/bspace";

if i print the bs i will get -- this is my bacspace

then i will use it at the end of the string literal like below

String bs="this is my backspace/b";

if i prints bs, the output is --this is my backspace

My doubt is ,why /b has no effect when used at the end of a string literal?



thanx

johnson
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"johnson" please read our JavaRanch Naming Policy. We encourage you to use your real name in the format <first name> <family name>. You can change your displayed name via the My Profile link.
Thanks,
-Barry


(NR)
[ May 25, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
An escape sequence uses the back slash "\" not the forward facing slash "/".
So use "\b", not "/b".
The behaviour will also depend on how the output device handles the backspace character.
Johnson David
Greenhorn

Joined: May 22, 2005
Posts: 27
Sorry Barry Gaunt, i havent read about ur naming convesion ,ok now i changed my profile , also my question is wrong i have used backspace symbol as /b instead of \b





thanx

johnson
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11246
    
  16

backspace is not a delete. so when you have "this is my back/bspace", you start printing the characters in order...

b...a...c..k... then you back up one spot, and print b. this overwrites the k with a b.

in your second case, you print all the letters through the e, then back up one... but never overwrite the e with anything else, so it stays where it is.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
but never overwrite the e with anything else, so it stays where it is.[/QB]


why it doesn't overwrite e ?


Thanks and Regards, Amit Taneja
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
??? no reply ?
Alan Jump
Greenhorn

Joined: May 25, 2005
Posts: 26
Originally posted by amit taneja:


why it doesn't overwrite e ?


Because the 'e' is at the end of the output string; there's nothing after the \b to overwrite it with. So the 'e' gets sent to the output device, then the output device is told to back up one space...and that's it. If the intent was to have the 'e' overwritten/removed, the string should have been something like Note the trailing space; that will overwrite the 'e'.

Hope this helps...
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11246
    
  16

think of a backspace as hitting the left arrow key on your keyboard (and you have the "insert" turned off). if i type the letters

"abcde"

and then hit the left arrow, the cursor is between the d and e. if that's ALL i do, the e does not get overwritten. you haven't given it anything to overwrite the 'e' WITH. it's sitting there, saying "ok, i backed up to re-write whatevers in that spot, just tell me what it is..." but then you say "we're done writing - you can quit now", so the 'e' never gets written over, so it stays there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: small doubt in escape sequences