473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Replace special character

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
3 2604
cnsabar
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
4,059 Expert 2GB
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
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

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

Similar topics

17
by: Pikkel | last post by:
i'm looking for a way to replace special characters with characters without accents, cedilles, etc.
14
by: Etu | last post by:
Hi, I have a string: string c = "'abc' \"cde\", 'mno' \"xyz\","; how can I use the c.Replace(???, ???) method to have this string: "'abc' "cde", 'mno' "xyz"," that is, all the...
3
by: gogaz | last post by:
Hi there, I have a small problem. I need to replace the "?" character from user input string to "-". I have tried: Regex.Replace(sStr,"\?","-"); //GIVES ERROR Regex.Replace(sStr,@"?","-");...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
6
by: Peter.Laganis | last post by:
Hi to all, I apologize in advance if a similar question was already posted, but I didn't find it. Here is my problem: I would like to replace all the special characters ' ¾' with another...
6
by: Gabriel | last post by:
Hello, I do this : s = Environment.CurrentDirectory; s = s.Replace("\\", @"\"); Environment.CurrentDirectiry return a path like this C:\\....\\....\\..... I'd like replace the \\ by \, but...
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello, I have some XML that is returned to my application from another vendor that I cannot change before it gets to me. I can only alter it after it gets to my application. That being said, I...
8
by: Kurt Peters | last post by:
I'm using the code below to read a pdf document, and it has no line feeds or carriage returns in the imported text. I'm therefore trying to just replace the symbol that looks like it would be an...
5
by: shapper | last post by:
Hello, I have a text as follows: "My email is something@something.xyz and I posted this @ 2 am" I need to replace the @ by (AT) bu only the ones that are in email addresses. All other @...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.