How to parse the text which I get form the richTextBox1, so I could get all the strings closed by " " and put them to the richTextBox2 I thought it should be easy, but get stuck. So any help will be appreciated.
I'm using switch/case, because I have to add more cases later(numbers, letters, comments and other characters). So here is my code...
richTextBox2.Clear();
string s, rezultat = "", result = "";
s = richTextBox1.Text;
int i = 0, j = 0, start, final;
while (i < s.Length)
{
switch (s[ i ])
{
case '"':
{
//example aaa"abc"ggg"123"rrr"456"ddd
i++;
if (j < 2)
{
j = j + 1;
start = s.IndexOf("\"") + 1;
final = s.IndexOf("\"", start);
s = s.Remove(start, final - start);
}
else { j = 0; }
richTextBox2.Text += " - " + s.Substring(start, final - start) + '\n';
} break;
default:
{
result += s[ i ];
i++;
richTextBox2.Text += "OtherSymbol - " + result + '\n';
result = "";
} break;
}

String question
chris27uk
string source = null;
string destination = null;
const char seperator = '"';
int index = source.IndexOf( seperator );
while( index != -1 )
{
int startIndex = index;
int endIndex = source.IndexOf( seperator, startIndex + 1 );
if( endIndex != -1 )
{
destination += source.Substring( startIndex, endIndex );
index = source.IndexOf( seperator, endIndex + 1 );
}
else
{
break;
}
}
biglc1
Here is some changed code, i only added some checks but i can see some thing over the head because i wrote it out of the head:
string source = null;
string destination = null;
const char seperator = '"';
int index = source.IndexOf( seperator );
while( index != -1 )
{
if( (index + 1) >= source.Lenght )
{
break;
}
int startIndex = index;
int endIndex = source.IndexOf( seperator, startIndex + 1 );
if( endIndex != -1 && endIndex < source.Lenght )
{
destination += source.Substring( startIndex, endIndex );
if( (endIndex + 1 ) >= source.Lenght )
{
break;
}
index = source.IndexOf( seperator, endIndex + 1 );
}
else
{
break;
}
}
usman_kec
I' ll try to see if I can solve this problem by myself.