Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple string replace question

 
Ravi Shankarappa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

In a string, how do I replace all occurrences of "\" by "\\" ?.

Thanks in advance.

-Ravi
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By using String.replace(CharSequence, CharSequence) - String implements CharSequence so you can use String literals. Unlike String.replaceAll, this method doesn't take regular expressions so you need a lot less escaping.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic