By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,848 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,848 IT Pros & Developers. It's quick & easy.

Replace special character

P: 41
Can somebody help me,

Take any string from command line prompt & replace what ever special character will get in that string that should be replaced with \ character.

Ex:
Enter any string: xyz/plks/abc.txt/$

Out put should be like this:
xyz\/plks\/abc\.txt\/\$

Thanks
Dillip
May 9 '08 #1
Share this Question
Share on Google+
3 Replies


P: 40
Hi.,

Try this.,
Expand|Select|Wrap|Line Numbers
  1. $InputString=~s#(\W)#\\$1#gi;
  2.  
Can somebody help me,

Take any string from command line prompt & replace what ever special character will get in that string that should be replaced with \ character.

Ex:
Enter any string: xyz/plks/abc.txt/$

Out put should be like this:
xyz\/plks\/abc\.txt\/\$

Thanks
Dillip
May 9 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
or try the quotemeta() function:

Expand|Select|Wrap|Line Numbers
  1. $foo = 'xyz/.?.!@#$%^&*()_+/abc';
  2. $foo = quotemeta($foo);
  3. print $foo;
May 9 '08 #3

P: 41
Hi.,

Try this.,
Expand|Select|Wrap|Line Numbers
  1. $InputString=~s#(\W)#\\$1#gi;
  2.  

Thanks~
Now it is working fine.
May 15 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.