Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing special characters from a String

 
Manish Dhasmana
Greenhorn
Posts: 18
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ July 24, 2008: Message edited by: Piet Verdriet ]
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic