Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove special characters & spaces in a string 1

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hi all, How can i remove all the special character and spaces from a string.

$test="7797 telegraph rd, apt # B22,city,state";

Output:

7797telegraphrdaptb22citystate

I tried something like this

$test="7797 telegraph rd, apt # B22,city,state";
$test=~s/ //g; #remove all the spaces in the sting

$test=~/(a-zA-Z0-9)/;

$output=$1;
#I try to match alphanumeric alone and capture it a string it didn't work :(

it prints out null..

any thoughts ..?

Thank you.


 
Thank you tony.

Code:
$test="7797 telegraph rd, apt # B22,city,state";
$test=~s/[^a-zA-Z0-9]//g; #removes all spaces & special characters

output:
7797telegraphrdaptB22citystate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top