Answer the question
In order to leave comments, you need to log in
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
if (!string.IsNullOrEmpty(match.ToString())
Storage.AppendText(match.ToString());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question