Answer the question
In order to leave comments, you need to log in
Need implementation advice?
Hello. There is a component on the form 2 richtextbox components, I insert text into them. The text may contain spaces.
In the future, I need to compare these 2 lists and leave only the text that is not, for example, in richtextbox1. As I see the comparison of these lists: - I
place all the words in a column, sort and compare line by line - if they match, then delete the line, etc. But this approach is not the best. How to implement the plan??? I'm not asking you to code.
Answer the question
In order to leave comments, you need to log in
Hey!
If I understand everything correctly, then the first thing that comes into my head (without connecting third-party frameworks) is to split the string into an array and compare them. Just overkill. You may be afraid of manual implementation, but under the hood of frameworks is basically something like this. Unless the algorithm is somehow screwed up.
richtextbox = "You win some. You lose some.";
richtextbox1 = "You not win amazing some. You lose down some.";
string[] textsubs = richtextbox.Split(' ');
string[] textsubs1 = richtextbox1.Split(' ');
foreach (var sub in textsubs )
{
foreach (var sub1 in textsubs ){
// делаем цикл сравнивания и удаления из массива.
var res = String.Equals( sub, sub1)
.....
}
}
1) Split the text into words using Split, as described above.
2) Place the results in a HashSet
3) Exclude another from one set. ExceptWith method.
Found this solution:
double[] numbers1 = { 2.0, 2.0, 2.1, 2.2, 2.3, 2.3, 2.4, 2.5 };
double[] numbers2 = { 2.2 };
IEnumerable<double> onlyInFirstSet = numbers1.Except(numbers2);
foreach (double number in onlyInFirstSet)
Console.WriteLine(number);
/*
This code produces the following output:
2
2.1
2.3
2.4
2.5
*/
private void button1_Click(object sender, EventArgs e)
{
list1.Add(textBox1.Text);
list2.Add(textBox2.Text);
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox3.Clear();
IEnumerable list3 = list1.Except(list2);
foreach (string c in list3)
{
richTextBox3.Text = c;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question