• Post Reply Bookmark Topic Watch Topic
  • New Topic

Character replacement  RSS feed

 
Bryon Phinney
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp form where users may type or copy and paste text in. I then save it to an xml file and later pull it back out for display.

The problem I am having is that sometimes the single and double quotes that are typed(depending on the font) or pasted from another word processor are not valid characters when JDOM tries to read the saved file.

I need to find and replace the offending character with another character (straight single or double quote).

What is the best way to do this?

Thanks for any help you can give.
Bryon
 
Darin Niard
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darin Niard's code might be enough for replacing characters, but if you do need more assistance. I do recommend you to provide your code as an example,Bryon Phinney...
 
Bryon Phinney
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do need more assistance and I guess this is a two part question.

Part 1 - I am not exactly sure what characters I need to replace, I see several characters for double quotes (I also am having trouble with single quotes and the dash) Why does JDOM or java seem to only know about a \u0022?

Part 2 - The Code
When I do this:
Integer.toHexString( input.charAt(i))
I get this:
for a left double quote I get a "93"
for a right double quote I get a "94"

I have also seen the characters \u201C and \u201D listed as left and right double quotes.

I need all these and any other doulble quote characters to be \u0022.

The problem is that when I do this in my String helper class:
validXml = validXml.replaceAll("\u201D", "\u0022") the \u0022 is interpreted as the closing quote for the second string and then there is a compile error.

Thanks again
Bryon
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, why do u have to use the HEX code of the quotes? If you apply the real ' and " in the replaceAll method, it would be easier to convert, I guess...
 
Bryon Phinney
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now I'm gun-shy about what character I am really getting when I type one in from the keyboard. I just want to ensure I am getting the 22 double quote.

I can go with that for now.

Is it the different fonts that determine which character gets used? The type of encoding?

Thanks
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bryon Phinney:
Is it the different fonts that determine which character gets used? The type of encoding?


I don't think Fonts matter, but Encoding does... So it would be better to check the encoding of the characters out again... I'm sorry, if my assistance doesn't help you much...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!