views:

365

answers:

4

Using C# .net I am parsing some data with some partial html/javascript inside it (i dont know who made that decision) and i need to pull a link. The link looks like this

http:\/\/fc0.site.net\/fs50\/i\/2009\/name.jpg

It came from this which i assume is javascript and looks like json

"name":{"id":"589","src":"http:\/\/fc0.site.net\/fs50\/i\/2009\/name.jpg"}

But anyways how should i escape the first link so i get http://fc0.site.net/fs50/i/2009/name.jpg

In this case i could just replace '\' with '' since links dont contain \ nor " so i could do that but i am a fan of knowing the right solution and doing things properly. So how might i escape this. After looking at that link for a minute i thought is that valid? does java script or json escape / with \? It doesnt seem like it should?

+1  A: 
Colour Blend
I think you misread a part. I already do "" in my C# strings and dont see why you mentioned that. I asked how do i escape the 1st string in C#.
acidzombie24
@acidzombie24: sorry about that. I'll read well next time. Hope my answer helps you.
Colour Blend
A: 

Odd, it doesn’t look like any JavaScript/JSON escaping you’d expect. You can have forward slashes in JavaScript strings just fine.

Paul D. Waite
A: 

Why dont you try a regex on the escaped slashes to replace them in the C# code...

String url = @"http:\/\/fc0.site.net\/fs50\/i\/2009\/name.jpg";

String pattern = @"\\/";

String cleanUrl = Regex.Replace(url, pattern, "/");

Hope it helps!

Chalkey
A: 

Actually you want to unescape the string. Answered in this SO thread.

Amnon