Removing special characters from a String

Hello everyone, I am reading a string from a JTextArea which contains special characters such as " and , and \etc. I want to assign this data to a string but it is generating exception for these special characters. I know that we can assign these special characters to a string by using a backslash(\) before the special symbol. The problem is the data in the JTextArea is not entered by anyone but it is generated from somewhere else. So, how can I assign this JTextArea data to the string and then replace these special characters later with a whitespace. Thank you very much in advance

Not quite, Piet. But I'm wondering why the string contains backslashes in the first place. For instance, if the character following the backslash is 'n', maybe the two characters are meant to be interpreted as an escape sequence, and you should replace them both with a linefeed. But if you really just want to get rid of those characters, shouldn't you replace them with an empty string instead of a space?

Piet Verdriet
Ranch Hand

Joined: Feb 25, 2006
Posts: 266

posted Jul 25, 2008 07:03:00

0

Originally posted by Alan Moore: Not quite, Piet.

But, of course uncle_al..., err, I mean Alan! Silly me!

... But I'm wondering why the string contains backslashes in the first place. For instance, if the character following the backslash is 'n', maybe the two characters are meant to be interpreted as an escape sequence, and you should replace them both with a linefeed. But if you really just want to get rid of those characters, shouldn't you replace them with an empty string instead of a space?[/qb]

My thoughts exactly. But it appears the OP has left the virtual building.