Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java replace all non alphanumeric
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Deepak Kumar
Java replace all non alphanumeric
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


Hi,

In Java how to replace all non alphanumeric characters with blank? Share me the best code for java replace all non alphanumeric.

Thanks


Advertisement
View Answers

March 29, 2011 at 11:36 AM


Hi,

You can use the replaceAll() function of String class in Java.

We will use the regular expression "[^a-zA-Z0-9]" for finding all non alphanumeric characters and then replace it with required character.

Following example show how to replace all non alphanumeric characters present in a Java String variable.

public class TestReplaceAllNonAlphanumeric 
{
    public static void main(String[] args) 
    {
    String s = "What is use of[]. What {} is used.";
    s = s.replaceAll("[^a-zA-Z0-9]", "");
    System.out.println(s);
    }
}

Thanks



Related Tutorials/Questions & Answers:
Java replace all non alphanumeric
Java replace all non alphanumeric  Hi, In Java how to replace all non alphanumeric characters with blank? Share me the best code for java replace...]" for finding all non alphanumeric characters and then replace it with required
MySQL replace all non alphanumeric characters
MySQL replace all non alphanumeric characters  Hi, How to replace all non alphanumeric characters in MySQL? Thanks
Advertisements
Java String : Replace All
Java String : Replace All This section defines how to replace all character with specified character without using system methods. Replace All method : You can replace all specific character in a given string with another character
find and replace in java
find and replace in java  Need 'find and replace' function in Java to find special keyword in XMl such as @,#,!,%..and replace with their corresponding entities
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
Non-virtual Methods in Java - java tutorials
The better way to achieve the non-virtual function in java is that make all...: #000000; } Non Virtual Methods in Java Lets see the concept of virtual... hierarchy. In Java programming language all the methods are virtual, i.e.
javascript regex validation alphanumeric
regex validation for alphanumeric?   <html> <head> <title> alphanumeric validation using regex</title> <script type="text...}$/; if (pattern.test(name)) { alert(name +" has alphanumeric value
Alphanumeric Validation in JavaScript
Alphanumeric Validation in JavaScript In this tutorials we will discuss about alphanumeric validation in JavaScript. Sometimes it may occur when user have... to validate a form which can accept only character and digit in java Script
Non Editable Text File in java - Java Beginners
Non Editable Text File in java  Hello Sir ,I want to Show NonEditable TextFile on JButton Click which Contains User Manual of Project ,How I can Do It. plz Help Me
About search and replace contains of .doc or .docx file using java.
About search and replace contains of .doc or .docx file using java.  Hi , I am trying to replace contents of ms.word document in .doc or .docx... any one tell me how could I replace them using java
ereg_replace() and eregi_replace().
ereg_replace() and eregi_replace().  What is the difference between eregreplace() and eregireplace()?   Hi friends, ereg_replace() is case sensitive like "Bharat"cannot be treated as "bharat"and eregi_replace
Java delete non empty directory
Java delete non empty directory This section demonstrates you how to delete a non empty directory. It is easy to delete a directory if it is empty by simply... it is necessary to recursively delete all the files and subdirectories
Accessing non-static members through the main method in Java.
Accessing non-static members through the main method in Java.  As an oop rule, a static method can have access only to static variables and static... in Java has access to non-static members (variables or methods) even though
java script to replace words starting and ending with tild(~) symbol in a text area with the word highlighted yellow.
java script to replace words starting and ending with tild(~) symbol in a text... requirement we have to replace all the occurence of such words and replace with highlighted text. for example: The script should findout all the occurence of the words
Replace TEXT
Replace TEXT   I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
Making a Frame Non Resizable in Java
Making a Frame Non Resizable in Java       This program illustrates you how to make a frame non... the boolean value false to the setResizable() method then the frame will be non
Java Print the all components
Java Print the all components  This is my code. Please tell me the solutions import javax.swing.table.*; import javax.swing.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; import
hi all - Java Beginners
hi all  hi, i need interview questions of the java asap can u please sendme to my mail   Hi, Hope you didnt have this eBook. You can download this at thislink... http://www.4shared.com/file/45195248/1f297b96
Making a Frame Non Resizable in Java
Making a Frame Non Resizable in Java   ... a frame non resizable. It means that the disabling the maximize button... then the frame will be non-resizable otherwise frame will be resizable
MySQL Replace
MySQL Replace       MySQL Replace function finds and replaces the occurrences of specified string...: REPLACE( String_Text, String_FROM, String_TO); where String_Text
What is the difference between ereg_replace() and eregi_replace()?
What is the difference between ereg_replace() and eregi_replace()?  What is the difference between eregreplace() and eregireplace
replace character in php
replace character in php  PHP script that replace character
MySql find and replace string
MySql find and replace string  How to find and replace string or special characters in MySql & PHP?   Find and Replace String PHP $result = preg_replace('/\band\b/i', 'foo', $subject
non empty file
Java Delete non empty file  f.delete() works when the file is empty.if a file be non empty how to delete it???   Please visit the following link: http://www.roseindia.net/tutorial/java/core/files
regexp_replace in update and replace query in postgres
regexp_replace in update and replace query in postgres  update message set data = replace (data, 'wmost','westernmost'); April 4, 2011 at 5:04 PM.... is there a way to avoid this problem. Can you send similar query using regexp_replace
Difference between translate and replace
Difference between translate and replace   hiii, What is the difference between translate and replace?   hello, Replace replace every.... this work for entire word and pattern,. Translate replace the one charecte
clustered and a non-clustered index?
clustered and a non-clustered index?  What is the difference between clustered and a non-clustered index
default password Allow the user to see the typed alphanumeric or character before it is changed to an encrypted dot
default password Allow the user to see the typed alphanumeric or character before it is changed to an encrypted dot  Allow the user to see the typed alphanumeric or character before it is changed to an encrypted dot in xsl n
Non SOAP webservices - WebSevices
Non SOAP webservices  How can i build non-SOAP (XML) based... option other than REST to implement non-soap webservices? Do we have WSDL incase of non-soap webservices
Plz provide me all the material for Java
Plz provide me all the material for Java  Plz provide me all the material for Java   Please go through the following link: Java Tutorials
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
Advertisements
 

 

 

DMCA.com