Y
Y
Yuri Vasilchenko2016-07-17 12:47:55
C++ / C#
Yuri Vasilchenko, 2016-07-17 12:47:55

How can I fix the loop so that it only adds one transition (Loop + regex)?

I have a text file, I wrote an algorithm using a loop that searches for text between double quotes on each line, writes it to a richtextbox in a column, but when it does not find text between "tags", it makes a transition. How to avoid it?

if (ofd.ShowDialog()== DialogResult.OK)
            {
                StreamReader sr = new StreamReader(ofd.FileName);
                string line = sr.ReadLine();
                string id = "(?<=\")(.*)(?=\")";
                while (line !=null)
                {
                    var match = Regex.Match(line, id );
                    Storage.AppendText(match.ToString());
                    line = sr.ReadLine();
                }
                sr.Close();
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zelimkhan Beltoev, 2016-07-17
@Carloman

if (!string.IsNullOrEmpty(match.ToString())
   Storage.AppendText(match.ToString());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question