• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

escape sequences

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Got a simple question. I am trying to print text to file. I am having trouble with this line:
out.println("errorMsg += \"'\n''\n'\"+(errCount+1)+\". Name not specified\";");
I keep getting new lines in the text file rather than having \n print out twice. I thought that placing it in single quotes would allow for the character literals to print out rather than the new line. any help would be appreciated.

Thanks!
Ronald
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rather than use '\n', have you tried \\n?
This code:

yields this output:
C:\Temp>java Trial
errorMsg += "\n\n"+(errCount+1)+". Name not specified";
C:\Temp>
 
Ronald Whalen
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. Tried that too. Finally got it to work by using the concat operator to break up the string along the lines of
..+"\\"+"n"+
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic