This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Removing special characters from a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Removing special characters from a String" Watch "Removing special characters from a String" New topic
Author

Removing special characters from a String

Manish Dhasmana
Greenhorn

Joined: Aug 25, 2007
Posts: 18

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
Piet Verdriet
Ranch Hand

Joined: Feb 25, 2006
Posts: 266

[ July 24, 2008: Message edited by: Piet Verdriet ]
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
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
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.

Regards,

Piet (aka prometheuzz)
[ July 25, 2008: Message edited by: Piet Verdriet ]
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
Originally posted by Piet Verdriet:
Piet (aka prometheuzz)

I thought there was something familiar about you. Then again, maybe it was just that scorched-ego smell that always lingers around people who've been participating in the Sun forums.
Manish Dhasmana
Greenhorn

Joined: Aug 25, 2007
Posts: 18

Can you please send me code snippet to do this, I tried to replace it with a space but can't!! Hoping for a final solution. Post the solution considering the following string for input..

Specify first corner point or [Chamfer/Elevation/Fillet/Thickness/Width]:
Specify other corner point or [Dimensions]:
Command: Specify opposite corner:
Command: li
LIST 1 found

LWPOLYLINE Layer: "0"
Space: Model space
Handle = 89
Closed
Constant width 0.0000
area 17.1232
perimeter 18.5024

at point X= 11.4358 Y= 22.2415 Z= 0.0000
at point X= 18.1285 Y= 22.2415 Z= 0.0000
at point X= 18.1285 Y= 19.6830 Z= 0.0000
at point X= 11.4358 Y= 19.6830 Z= 0.0000
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42032
    
  64
How did you try? Show us your code. People here will not solve the problem for you, but we'll help you solve it yourself.


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Removing special characters from a String