• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String escape

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • 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


 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
The system the output is fed is a RDF Store database
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic