Open text file, loop through contents and check against

后端 未结 5 2232
清酒与你
清酒与你 2020-12-21 17:24

So I have a generic number check that I am trying to implement:

    public static bool isNumberValid(string Number)
    {
    }

And I want to

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-21 17:53

    You could try this to keep with the pattern you were initially following...

    private void button1_Click(object sender, EventArgs e)
    {
        DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
        if (result == DialogResult.OK) // Test result.
        {
            string file = openFileDialog1.FileName;
            try
            {
                using (var reader = new StreamReader(file))
                {
                    using (var writer = new StreamWriter("results.txt"))
                    {
                        string currentNumber;
                        while ((currentNumber = reader.ReadLine()) != null)
                        {
                            if (IsNumberValid(currentNumber))
                                writer.WriteLine(String.Format("{0} true", currentNumber));
                        }
                    }
                }
            }
    
            catch (IOException)
            {
            }
        }
    }
    
    public bool IsNumberValid(string number)
    {
        //Whatever code you use to check your number
    }
    

提交回复
热议问题