I have to be able to split readed line of code by File.ReadLines() by ';' when i got something like that in source code (two or more code lines in one line):
string firstString = "xyzxyz"; string secodnString = "zyxzyx";
the problem is that inside those strings can be another ; or even ", and then this line:
string firstString = "xyz;xyz\"inside quote\""; string secondString =
"zyx;zyx";
readed looks like this:
"string firstString = \"xyz;xyz\\\"inside quote\\\"\"; string secondString
= \"zyx;zyx\";
So I figured that I can determine if ';' is inside string due to difference in \" and \\" by Regex, but i cant figure aout how to match \" but not to match \\" i've tried:
"[^\\\\]\"" or "[^\\]\""
but it does not work. Thanks in andvace.
EDIT, my only problem is the regex, rest of it i got already writen like that:
List<string> vrlSplitedLine = vrlLines[i].Trim().Split(';').ToList();
List<string> vrlFinallSplitedLine = new List<string>();
string vrlReatachedString = string.Empty;
for(int j = 0; j < vrlSplitedLine.Count; j++)
{
if(Regex.Matches(vrlSplitedLine[j], "[^\\\\]\"").Count % 2 != 0)
{
vrlReatachedString = vrlSplitedLine[j];
int k = j;
do
{
k++;
vrlReatachedString = vrlReatachedString + ';' + vrlSplitedLine[k];
}
while (Regex.Matches(vrlSplitedLine[k], "[^\\\\]\"").Count % 2 == 0);
vrlFinallSplitedLine.Add(vrlReatachedString);
j = k;
}
else
{
vrlFinallSplitedLine.Add(vrlSplitedLine[j]);
}
}