I have this string:
(335, 'Anschutz 1710/1712', '<p>rn <a href="" onclick="window.open(this.href, '', 'resizable=no,status=no,location=no,toolbar=no,menubar=no,fullscreen=no,scrollbars=no,dependent=no'); return false;"><img alt="" src="" style="width: 780px; height: 659px;" /></a></p>rn', 1, 17, '', '', '', '', 0, '', 0, 0, 88, '', 0),
And I’ve been trying to deserialize it, but I need to get rid of the characters with in front of them. So I tried doing a simple
if(character == '\')
to match it, but that only catches the second '
after this.href
, meaning that somehow it skipped 5 backslashes before suddenly stopping on this one.
This is the code I’ve written to deserialize the string:
public static string[] RipASQLQuery(string data)
{
// Remove the SQL stuff
var str = data.Replace("(", "");
str = str.Replace(")", "");
str = str.Replace(";", "");
var list = new List<string>();
int i = 0;
bool inSubstring = false;
bool escaped = false;
foreach (var character in str.ToCharArray())
{
if (list.Count < i + 1)
{
list.Add("");
}
if (escaped)
{
// Ignore this character
Console.WriteLine("Escaped " + character);
escaped = false;
continue;
}
if (inSubstring)
{
if (character == ''')
inSubstring = false;
list[i] += character;
continue;
}
if(character == ('\')
{
Console.WriteLine("Backslash!!");
escaped = true;
continue;
}
else if (character == ''')
{
inSubstring = true;
list[i] += character;
continue;
}
else if(character == ',')
{
i++;
continue;
}
else
{
list[i] += character;
}
}
return list.ToArray();
I tried to str.Replace("\", "|");
to try to see if I can match a different character, which successfully changed the string to:
335, 'Anschutz 1710/1712', '<p>|r|n <a href=|"|" onclick=|"window.open(this.href, |'|', |'resizable=no,status=no,location=no,toolbar=no,menubar=no,fullscreen=no,scrollbars=no,dependent=no|' return false|"><img alt=|"|" src=|"|" style=|"width: 780px height: 659px|" /></a></p>|r|n', 1, 17, '', '', '', '', 0, '', 0, 0, 88, '', 0,
But it still gets caught at the second |'
after this.href
. I’m very confused.