• 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

String escape

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a set of strings that are not escaped for the '\' and '"' (slash & quote) characters. So I have written below code to escape the Strings with '\' character. Since there are thousands of such input Strings to be checked for proper escape, I just want to know any API method is there for properly escaping an usescaped string. I fear calling my method thousands of times will hit the applications performance . Thank you


 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'escaping' is only normally only needed in String literals within your Java source code. What makes you think you need to further escape some characters?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Sabre wrote:'escaping' is only normally only needed in String literals within your Java source code. What makes you think you need to further escape some characters?


Ok.. I am creating a text file in java that will be fed to another System (a RDF database store). The text file created is having strings that are not escaped like below
"A "doctors" day"
"A PF\VPF Issue"
If you see in the two strings the first has two quotes(") that are not escaped & "\" in second string (PF\VPF) not escaped. Since the input strings are read from an XML (not well formed - source of error) i have to escape it now before feeding them to the System else which will throw the exact error -

\n, \r, \t, \", \\, \u or \U should be escaped

 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote: Since the input strings are read from an XML (not well formed - source of error) i have to escape it now before feeding them to the System



I don't follow this. Strings are not "read from an XML". Any good system generating an XML file will behind the scenes do any 'escaping' it needs to to make sure that the resultant XML is well formed. What 'System' are you feeding the strings into that does not do this?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The system the output is fed is a RDF Store database
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote:The system the output is fed is a RDF Store database



I would expected the "RDF Store database" to performed any necessary escaping (separation of concerns). You need to check the documentation for the database.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic