• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking for java special characters in a string

 
N Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
N Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you have any sample example to handle this.
 
Henry Wong
author
Marshal
Pie
Posts: 21417
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:I would recommend starting with a tutorial on regular expressions.

Henry
And here is such a tutorial
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic