Link to home
Start Free TrialLog in
Avatar of noshankus
noshankusFlag for Ireland

asked on

Replace all instances of \ with /

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,
Avatar of prady_21
prady_21

This works well
hope it helps

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

Avatar of noshankus

ASKER

Nope! Sorry... but you sure you got the right syntax?

I want to replace all \ with /

Those damn commands hurt my eyes!!
Nope! Sorry... but you sure you got the right syntax?

I want to replace all \ with /

Those damn commands hurt my eyes!!
i just tested it in my system, it is working absolutely fine
just cut and copy what is given, it shld work
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 :)
ASKER CERTIFIED SOLUTION
Avatar of prady_21
prady_21

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and that is the reason why you are getting spaces in your output and not \
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 :)
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!
Can you just give an idea of from where you are getting the text from, and can you just put a piece of code

Much appreciated :)
Can you just give an idea of from where you are getting the text from, and can you just put a piece of code

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