DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Perl (http://www.daniweb.com/forums/forum112.html)
-   -   substitute a string (http://www.daniweb.com/forums/thread158950.html)

localp Nov 22nd, 2008 12:28 pm
substitute a string
 
i am reading a url and inthat i have an array that has stored the value of a string as follows

address=no+3%2C+oxford+street

in this wat i want is to display the address as

"no 3 oxford street"

some one please give me the code to write this as the output i want...

KevinADC Nov 22nd, 2008 2:00 pm
Re: substitute a string
 
There are other ways, but here is one:

my $string = 'address=no+3%2C+oxford+street';
(my $key,$value) = split(/=/,$string);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
print $value;

localp Nov 22nd, 2008 4:07 pm
Re: substitute a string
 
Quote:

Originally Posted by KevinADC (Post 742195)
There are other ways, but here is one:

my $string = 'address=no+3%2C+oxford+street';
(my $key,$value) = split(/=/,$string);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
print $value;


it worked thanks !!

KevinADC Nov 22nd, 2008 6:22 pm
Re: substitute a string
 
actually there was an error in this line:

(my $key,$value) = split(/=/,$string);

should have been:

my($key,$value) = split(/=/,$string);


All times are GMT -4. The time now is 7:03 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC