Solved

Substituting whitespace for +

Posted on 2002-03-27
2
258 Views
Last Modified: 2010-05-18
Hi,
I am trying to replace all the + in a string for whitespace. But I can't seem to be able to find the + in the string.
Any ideas?

Thanks,
Angelmoon
0
Comment
Question by:angelmoon
2 Comments
 
LVL 5

Expert Comment

by:Peewee
ID: 6899887
angelmoon,
is this what you want:

my $var = 'tie+tie';

$var =~ s/\+/ /ig;
print "var:$var\n";

regards
Peewee
0
 
LVL 5

Accepted Solution

by:
Sapa earned 100 total points
ID: 6899948
angelmoon,

it looks like you attempts to decode URL-encoded string.
Such strings can also contain %NN escape codes, which
represents characters with hexadecimal code NN. For example:
* is %2a, / is %2f etc.

There are at least 3 ways to decode such strings:

1. using URI::Escape module

use URI::Escape;
$decoded = uri_unescape($encoded);

2. using CGI module

use CGI;

$decoded = CGI::unescape($encoded);

3. Do it manually :(

$encoded =~ tr/+/ /;
$encoded =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now