zackmark29
Elite
This is the best method (for me) to avoid adding duplicate items and with match of your regular E×ρréššion
quick demo:
CODE:
quick demo:
CODE:
C#:
private void button1_Click(object sender, EventArgs e)
{
Regex httpRegEx= new Regex(@"(https.+|http.+)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
foreach (var item in listBox1.SelectedItems)
{
AddListBoxItemsWithRegEx(item.ToString(), httpRegEx);
}
}
private void AddListBoxItemsWithRegEx(string input, Regex pattern)
{
var newItems = pattern.Matches(input).Cast<Match>()
.Where(m => !listBox2.Items.Cast<string>()
.Any(item => item.Equals(m.Value, StringComparison.InvariantCultureIgnoreCase)))
.Select(m => m.Value).ToArray();
if (newItems.Any())
{
listBox2.BeginUpdate();
foreach (var item in newItems) {
listBox2.Items.Add(item);
}
listBox2.SelectedIndex = listBox2.Items.Count - 1;
listBox2.EndUpdate();
}
CountListBoxItems();
}
private void CountListBoxItems()
{
lblCount.Text = listBox2.Items.Count.ToString();
}