aspose file tools*
The moose likes Java in General and the fly likes Checking for java special characters in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Checking for java special characters in a string" Watch "Checking for java special characters in a string" New topic
Author

Checking for java special characters in a string

N Naresh
Ranch Hand

Joined: Nov 04, 2008
Posts: 66
Hi i want to check whether there is any java special character exist in a string or not. Could anybody help me on this.

Special Characters:

\!@#$%^*()_+|}{[]\:';"<>,./?
’ ’
‚ ‚
“ “
” ”
„ „
† †
‡ ‡
‰ ‰
‹ ‹
› ›
♠ ♠
♣ ♣
♥ ♥
♦ ♦
★ ★
☆ ☆
‾ ‾
← ←
↑ ↑
→ →
↓ ↓
™ ™
¢ ¢ ¢
£ £ £
¤ ¤ ¤
¥ ¥ ¥
¦ or &brkbar; ¦ ¦
§ § §
¨ or ¨ ¨ ¨
© © ©
ª ª ª
« « «
¬ ¬ ¬
­ ­ ¬
® ® ®
¯ or &hibar; ¯ ¯
° ° °
± ± ±
² ² ²
³ ³ ³
´ ´ ´
µ µ µ
¶ ¶ ¶
· · •
¸ ¸ ¸
¹ ¹ ¹
º º º
» » »
¼ ¼ ¼
½ ½ ½
¾ ¾ ¾
¿ ¿ ¿
À À À
Á Á Á
  Â
à à Ã
Ä Ä Ä
Å Å Å
Æ Æ Æ
Ç Ç Ç
È È È
É É É
Ê Ê Ê
Ë Ë Ë
Ì Ì Ì
Í Í Í
Î Î Î
Ï Ï Ï
Ð Ð Ð
Ñ Ñ Ñ
Ò Ò Ò
Ó Ó Ó
Ô Ô Ô
Õ Õ Õ
Ö Ö Ö
× × ×
Ø Ø Ø
Ù Ù Ù
Ú Ú Ú
Û Û Û
Ü Ü Ü
Ý Ý Ý
Þ Þ Þ
ß ß ß
à à à
á á á
â â â
ã ã ã
ä ä ä
å å å
æ æ æ
ç ç ç
è è è
é é é
ê ê ê
ë ë ë
ì ì ì
í í í
î î î
ï ï ï
ð ð ð
ñ ñ ñ
ò ò ò
ó ó ó
ô ô ô
õ õ õ
ö ö ö
÷ ÷ ÷
ø ø ø
ù ù ù
ú ú ú
û û û
ü ü ü
ý ý ý
þ þ þ
ÿ ÿ ÿ
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Sounds like a case for using regular expressions. Since that's a finite group of characters, you can enumerate them all.

Or do you mean something like "everything but a-z, A-Z and 0-9"? That would be easier to accomplish using regexp groups and classes - check the javadocs of the java.util.regex.Pattern class.


Ping & DNS - my free Android networking tools app
N Naresh
Ranch Hand

Joined: Nov 04, 2008
Posts: 66
do you have any sample example to handle this.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

N Naresh wrote:do you have any sample example to handle this.


Regular expressions is probably one area where "learning by example" is not possible. You can't really learn regular expressions this way.

I would recommend starting with a tutorial on regular expressions.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Henry Wong wrote:I would recommend starting with a tutorial on regular expressions.

Henry
And here is such a tutorial
 
Don't get me started about those stupid light bulbs.
 
subject: Checking for java special characters in a string