Hi @LeaV , Welcome to Microsoft Q&A,
You have multiple ways to do it, such as using string.split.
Here you can use textbox.lines.tolist() to directly convert the data into a list.
Then use indexof to know the corresponding position.
private void button1_Click(object sender, EventArgs e)
{
List<string> list = new List<string>();
list = textBox2.Lines.ToList();
string SearchString = textBox1.Text;
String result = "";
foreach (string s in list)
{
if (s.Contains(SearchString))
{
result = list[list.IndexOf(s) + 1];
}
}
textBox3.Text = result;
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.