-1

I am parsing a source that frequently contains / encoded as \/. For example, https:// is encoded as https:\/\/.

What is the name of this encoding? It appreas to be used when sending json in HTML. It is a large document and / to \/ mapping probably isn't the only one used. What is the c# function to decode it?

Robert Segdewick
  • 543
  • 5
  • 17
  • 1
    Does the source document contain the literal characters \ followed by /? If not, this is just how [string escaping](https://stackoverflow.com/questions/10646142/what-does-it-mean-to-escape-a-string) works. – Scott Sep 25 '20 at 18:37
  • 2
    That's not an encoding that I'm familiar with. And, it's not something you generally see in a string with *escaped* characters. Where is this string coming from? – Flydog57 Sep 25 '20 at 18:39
  • 3
    What exactly is this "source"? Please provide more context. Slashes are rarely escaped or encoded, and even more rarely escaped in that way, although you *will* see that in regexes where the language uses the `/` character as the delimiter (e.g. Perl, JavaScript). – madreflection Sep 25 '20 at 18:44
  • I haven't found any literal \ characters. The document is a json response from a website. Using System.Text.RegularExpressions.Regex.Unescape(@"\/\/") seems to do the job – Robert Segdewick Sep 25 '20 at 18:48
  • Can you show an example of that response? Maybe someone will recognize it. If you don't know that it's a regex or that the extent of escaping matches that of regex, it might do something you neither expect nor want with an input you haven't seen yet. – madreflection Sep 25 '20 at 18:50
  • 1
    Perhaps you should add more details to the question (like the file type, where it came from, and sample file contents). And if you've found a solution, there is nothing wrong with answering your own question so others can learn from it. – Rufus L Sep 26 '20 at 00:21
  • `'\/'` is not recognized as a escape string in C#... Found that, first Google result: https://stackoverflow.com/questions/19930687/javascript-replace-or-to-single-slash –  Sep 26 '20 at 01:21

1 Answers1

0

Using System.Text.RegularExpressions.Regex.Unescape(@"\/\/") seems to do the job.

Robert Segdewick
  • 543
  • 5
  • 17