In my Java web app I pull a property from the database and send it to the view/browser layer via the controller.
In the HTML, I am expecting the string to look like this:
9" nails
Instead it looks like this:
"9\" nails"
So I plugged Apache StringEscapeUtils
into my service layer and ran unescapeJava()
on the property. The result became this:
"9" nails"
A slight improvement but still not right.
So my question is whether this is not just a String escaping issue but a more fundamental data issue. In other words, if what I have to do to achieve the desired output is to strip double quotes from the beginning and end of this property, there is a potential to affect other rows of data in unexpected ways - in which case I would have to visually inspect the entire database to make sure I am not displaying some other rows incorrectly based on the meaning of the double quotes character in those other strings.
Any direction here would be appreciated. Thanks.
It looks like some layer adds quotes to the front and back of each string. Without knowing more I suggest you do a simple str = str.substring(1, str.length() - 1)
to remove the two quotes that were added. We can't tell you if it's about some 'fundamental data issue" because we don't see anything else.
If you want to get really safe you can just use indexOf("\"");
and lastIndexOf("\"");
, see if they are respectively indices 0 and str.length() - 1
and if they are: strip them.