Total members 11890 |It is currently Fri Apr 19, 2024 4:24 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Hello,
I need a way out in Java to remove all special characters present in a String. Somebody please give me ideas.
Regards.




Author:
Newbie
User avatar Posts: 3
Have thanks: 0 time

what you think about this idea :

java code
public class Main {

    public static void main(String[] args) {
        String str="gasd@!dfas%";
        String newStr="";
          for (int i=0;i<str.length();i++)
          {
              //Ascci range for a-z A-Z
              if (str.charAt(i)>64&&str.charAt(i)<121)
              {
                    newStr+=str.charAt(i);
              }
          }

         System.out.println("String before filter "+str);
        System.out.println("String after filter "+newStr);

    }

}

 


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

For this message the author DrRakha has received gratitude : anubhab91

Thanks a lot. :-)


Author:
Newbie
User avatar Posts: 3
Have thanks: 0 time

That depends on what you define as special characters, but try replaceAll(...):
String result = yourString.replaceAll("[-+.^:,]","");


Author:
Newbie
User avatar Posts: 12
Have thanks: 1 time

For this message the author annaharris has received gratitude : anubhab91
Post new topic Reply to topic  [ 4 posts ] 

  Related Posts  to : How to remove special characters from a string in Java?
 Special Characters literals     -  
 Number of Occurrences of characters in a string     -  
 Remove all the vowels from a string     -  
 Unicode, ASCII, UTF-16, and UTF-8 characters in java     -  
 passing string value from java to .exe file     -  
 URL Characters and URL Encoding Values     -  
 continuously calculates the number of characters existing     -  
 Program to make a pyramid of characters based on input     -  
 recursive string reversal- reverse string     -  
 check if string ends with specific sub-string in php     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com