my dog learned polymorphism*
The moose likes Java in General and the fly likes String escape Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "String escape" Watch "String escape" New topic
Author

String escape

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Sep 07, 2004
Posts: 781

'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?


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Sep 07, 2004
Posts: 781

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
Bartender

Joined: May 31, 2011
Posts: 1776
The system the output is fed is a RDF Store database
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String escape