?
Solved

Replace all instances of \ with /

Posted on 2003-03-28
13
Medium Priority
?
190 Views
Last Modified: 2012-05-04
Hello,


I'm trying to replace all the instances of \ with /.

I have tried doing:

$content =~ s/\///g;
and
$content =~ tr/\///;

and many various versions trying to escape by adding an extra \ or two!!

Can anyone let me know if it's possible?

Thank you for your help and hints!
Best regards,
0
Comment
Question by:noshankus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 3

Expert Comment

by:prady_21
ID: 8224873
This works well
hope it helps

$value =~ s/\//\\/g;

0
 

Author Comment

by:noshankus
ID: 8224912
Nope! Sorry... but you sure you got the right syntax?

I want to replace all \ with /

Those damn commands hurt my eyes!!
0
 

Author Comment

by:noshankus
ID: 8224918
Nope! Sorry... but you sure you got the right syntax?

I want to replace all \ with /

Those damn commands hurt my eyes!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:prady_21
ID: 8224937
i just tested it in my system, it is working absolutely fine
just cut and copy what is given, it shld work
0
 

Author Comment

by:noshankus
ID: 8225018
Damn! I was so hoping you were wrong! :)

It still doesn't work on my system. I just get a space instead.
The input is some\thing and when it does it's stuff, I get some thing.

I can't even test it on my local system, as I'm having to do this online through a free provider. - Maybe that has something to do with it... but all the other swaps worked. Damn!

Any other ideas how I might go about this? - Extra help appreciated :)
0
 
LVL 3

Accepted Solution

by:
prady_21 earned 100 total points
ID: 8225078
i am terribly sorry, i will give it to you in a min, what my prog does is to replace / with \ .

and i am terribly sorry, but i still have the output
$value =~ s/\\/\//g;

but note ::: your $value has to be in single quotes

ie $value = 'some\something\somethng';

bcos if $value = "some\somthing\nothing\toomuch";
in " ", \ gives special meaning to the character
  ie \s becomes space, \t becomes tab and so on

i hope you understand
0
 
LVL 3

Expert Comment

by:prady_21
ID: 8225093
and that is the reason why you are getting spaces in your output and not \
0
 

Author Comment

by:noshankus
ID: 8225120
Oh I see.

Well, the problem is that the string could be quite long, as it's usually a path to a file:

some\thing\else\and\more\etc.jsp

So, you are saying that if the string (which is being sent from a form text area) is too long, then it will recognise all the \'s as spaces?

How would I get around that? :)

Thanks for your time, I really appreciate it :)
0
 

Author Comment

by:noshankus
ID: 8225151
I just did another swap that swapped the spaces with /

LOL! You'd think it would be easier!

Anyway, thank you very much for your help!
0
 
LVL 3

Expert Comment

by:prady_21
ID: 8225153
Can you just give an idea of from where you are getting the text from, and can you just put a piece of code

0
 

Author Comment

by:noshankus
ID: 8225160
Much appreciated :)
0
 
LVL 3

Expert Comment

by:prady_21
ID: 8225176
Can you just give an idea of from where you are getting the text from, and can you just put a piece of code

0
 
LVL 3

Expert Comment

by:prady_21
ID: 8225228
Well if you would like it, what you can do is, when you are getting the test, if there is some way you can pass the text as
$content = "some\\value\\somewhere\\something";

then there would be no problem
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
Six Sigma Control Plans

764 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