5 Replies - 857 Views - Last Post: 03 June 2010 - 04:09 PM Rate Topic: -----

#1 Guest_JavaMad*


Reputation:

using an escape character in a string

Posted 03 June 2010 - 06:35 AM

Hi new to Java and as such have a question,

I would like to use an escape character / in a string

so the following line of code

System.out.println("tail -f /dat/mydata/gps/ticks | egrep \ L\ \|\ VW\");

outputs

tail -f /dat/mydata/gps/ticks | egrep \ L\ \|\ VW\

Could someone help me out please. Your help will be much appreciated.

Many thanks

Is This A Good Question/Topic? 0

Replies To: using an escape character in a string

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: using an escape character in a string

Posted 03 June 2010 - 06:37 AM

Edit: nvm, messed up :P

This post has been edited by mostyfriedman: 03 June 2010 - 06:56 AM

Was This Post Helpful? 0
  • +
  • -

#3 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: using an escape character in a string

Posted 03 June 2010 - 06:43 AM

Umm, can't you simply print '/' in Java? You should be able to. '\' on the other side, must be followed by another '\', in order to get printed. Like:
System.out.println("Hello \\");


prints:
Hello \
Was This Post Helpful? 0
  • +
  • -

#4 Guest_JavaMad*


Reputation:

Re: using an escape character in a string

Posted 03 June 2010 - 06:43 AM

many thanks
Was This Post Helpful? 0

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2775
  • View blog
  • Posts: 11,737
  • Joined: 20-September 08

Re: using an escape character in a string

Posted 03 June 2010 - 07:42 AM

I'm not 100% what you're getting at with that command, but the following would be clearer

System.out.println("tail -f /dat/mydata/gps/ticks | egrep 'L|VW'");

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: using an escape character in a string

Posted 03 June 2010 - 04:09 PM

The escape character is \ not /
what a mess !!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1