substitute a string

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 102
Reputation: localp is an unknown quantity at this point 
Solved Threads: 2
localp localp is offline Offline
Junior Poster

substitute a string

 
0
  #1
Nov 22nd, 2008
i am reading a url and inthat i have an array that has stored the value of a string as follows

  1. address=no+3%2C+oxford+street
  2.  
  3. in this wat i want is to display the address as
  4.  
  5. "no 3 oxford street"

some one please give me the code to write this as the output i want...
Local P ...
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: substitute a string

 
0
  #2
Nov 22nd, 2008
There are other ways, but here is one:

  1. my $string = 'address=no+3%2C+oxford+street';
  2. (my $key,$value) = split(/=/,$string);
  3. $value =~ tr/+/ /;
  4. $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  5. print $value;
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 102
Reputation: localp is an unknown quantity at this point 
Solved Threads: 2
localp localp is offline Offline
Junior Poster

Re: substitute a string

 
0
  #3
Nov 22nd, 2008
Originally Posted by KevinADC View Post
There are other ways, but here is one:

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

it worked thanks !!
Local P ...
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: substitute a string

 
0
  #4
Nov 22nd, 2008
actually there was an error in this line:

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

should have been:

my($key,$value) = split(/=/,$string);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1230 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC