I have a textbox in which the user enters some string. Now, I extract a substring from the main string and display it into a listbox.
For example: If the user enters: SELECT A1,A2,A3 FROM TABLE1 then I need A1,A2 and A3 as separate items of my listbox.
I am able to do that easily, however there's a small problem that is occurring.
As soon as the user finishes typing the word "FROM", the values get added to the listbox and if the user types anything after "FROM"(even a space), the values get added again.
I need the values only once. What am I missing? Please help
private void textBox1_TextChanged(object sender, EventArgs e)
{
string substr;
string str = textBox1.Text.ToString();
Match m = Regex.Match(str, @"(?<=.\s+).+?(?=\s+from)", RegexOptions.IgnoreCase);
try
{
if (m.Success)
{
substr = m.Value;
string[] sub = substr.Split(',');
foreach (string x in sub)
{
listBox1.Items.Add(x);
}
}
finally
{
listBox1.EndUpdate();
}
}