S
S
Shoyo2021-08-25 13:30:41
C++ / C#
Shoyo, 2021-08-25 13:30:41

How to check if there is a number in a txt file?

I am making a phone book in C# Windows Forms NET. Unable to check if there is a number in the file. Always says no.
loginUser - text from TextBox

string loginUser = loginField.Text;
            string[] numbers = File.ReadAllLines(@"C:\Sharp_text\number2.txt");
            if(numbers.Contains(loginUser))
            {
                MessageBox.Show("Данные уже существуют!");
            }
            else
            {
                //File.AppendAllText(@"C:\Sharp_text\number2.txt", loginUser + Environment.NewLine);
                MessageBox.Show("Данные успешно добалены");
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-08-25
@Shoyo

Through foreach sort through an array and there will be a happiness.
foreach (loginUser in numbers)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question