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



Home Answers Viewqa Java-Beginners Java replace all non alphanumeric

Have Programming Question? Ask it here!
 
 
 


Deepak Kumar
Java replace all non alphanumeric
1 Answer(s)      3 years and a month 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
Programming - Replace method
Java: Programming - Replace method Change all occurrences in a string.... The predefined Java function replace may not be used for this -- you have to write... occurrence. Use a loop to replace all occurrences
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
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
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   ... a frame non resizable. It means that the disabling the maximize button... then the frame will be non-resizable otherwise frame will be resizable
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
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
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
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
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
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
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
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
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
Replace String in PHP - PHP
Replace String in PHP  What is the fastest way of replacing string in PHP Code?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Replace.html Thanks
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
like query and then update or replace
like query and then update or replace   In postgres i use like query to find the a specific word in a column for example in a column i have text... to replace or update "wmost" to "westernmost" in that text. is there a way to do
replace special characters in html
replace special characters in html  How can i replace the special characters in HTML?   Special Character in HTML HTML has a long list of special characters symbol that can be used anywhere throughout the HTML Code
java get all ip addresses in a lan
java get all ip addresses in a lan  Anybody have any idea on using java or cpp on how to get the ip addresses of all the machines[win or linux] connected to a computer in a LAN?. If this is not possible is there any function
Retrieve all the students in the same year(Java ArrayList)?
Retrieve all the students in the same year(Java ArrayList)?  ...); if(search != null){//if found 1 student by year do{//Search all students...;& !found_list.isEmpty()){ %> <html> "Displaying all the students
Site Map - All java tutorials
Site Map - All java tutorials In this section of sitemap we have listed all the important sections of java tutorials. Select the topics you want..., Spring, SQL, JSF and XML Tutorials.   These All Java Tutorials links
Replace JSF Standard Error Message
Replace JSF Standard Error Message  How can we replace the JSF Standard Error Message
Finding all palindrome prime numbers - Java Beginners
Finding all palindrome prime numbers  How do i write a program to Find all palindrome prime numbers between two integers supplied as input (start and end points are excluded
find all unique character in string using java
find all unique character in string using java  example: hello how are you. output should be waryu
Free Java Training
Free Java training is provided online by Roseindia for all the non.... Java being open source keeps expanding all the time. New technologies, methods... for expert Java programmers to fins all this updates and upgrades. This Java
How to Use Java Functions In EL
and static. It should have a non- void type return type. After all, its all the matter...How to Use Java Functions In EL          To use a Java Functions in  EL we
Greedy and Non-Greedy Matching in a Regular Expression
or the string or text in which all the characters of the search string is found. Non... Greedy and Non-Greedy Matching in a Regular Expression... a string in the given string through the Greedy and Non-Greedy way of matching
Replace broken Image using JQuery
Replace broken Image using JQuery  Sir My web page contains a lot of images. But when it will not loaded properly, it shows a broken image. How can...', 'missing.jpg'); } }); }) This code will replace the broken image
Should a main method be compulsorily declared in all java classes?
Should a main method be compulsorily declared in all java classes?  hi, Should a main method be compulsorily declared in all java classes? thanks... in all java classes. Where as the main method we should be defined only if the source
Reversing all root-to-leaf paths in a tree (JAVA) - Java Beginners
Reversing all root-to-leaf paths in a tree (JAVA)  A root-to-leaf path in a tree is defined to be a sequence of nodes starting from the root node... after reversing all root-to-leaf paths. For the following tree: root = 5
how to replace the values - Development process
how to replace the values  i have arraylist containing "or","c1","or","c2","c3","or",c4" i want the output as "c1","c2","c3","c4","or","or"  Hi friend, Code to solve the problem : import java.util.*; class
Get All Keys and Values of the Properties files in Java
Get All Keys and Values of the Properties files in Java... how to get all keys and it's values of the properties files in Java. Java provides the features to collection of all keys and values of the properties file
Get All Keys and Values of the Properties files in Java
Get All Keys and Values of the Properties files in Java... to get all keys and values of the properties files in the Java. This section illustrates the way for getting all keys and corresponding values of the properties
Advertisements
 

 

 

DMCA.com