• 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

Problem in finding " \' " in String or StringBuffer.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
in my program my need is to find \' in a string which i am reading from file.
now problem is java considering "\" as an escape char.
i cant change contents of file manually from "\'" to "\\'"

Help :
can someone help me in finding that.
or
is there anyway to off the escape char or to change escape character.
 
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
It looks like you are confused about Java considering \ as an escape character.

It is only the Java compiler that considers \ as an escape character in Java source code. The Java compiler does not have anything to do with the file your program is reading which contains the \ character. For your program, a \ in the input file is just like any other regular character; it's not handled as an escape character somehow.

You only need to write \\ instead of \ in the source code of your program. You do not need to change the file that your program is reading.

Show us your code and explain why it isn't doing exactly what you want it to do.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(Copied from locked thread in intermediate forum, just to save anyone recreating what I've put below - Think Jesper is probably right)
Not sure where you're going wrong , but it works on my machine
Are you sure String st contains what you think it contains ?

I just tried it out using the following class, the file test.txt contains one line as followsinsert into raexceptionlog (ErrorMsg) values ('The valid combination is \'R\' & \'-\' OR \'D\')

The result is
72
Pos found in file is 72

Note that if you're building the String up in the source code as in String st below you need the escape characters.

code:

 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic