c# - reading each line of text is still performing each line despite my attempted condition -


i'm reading each line of text, , if contains text warn. down warningstextbox.text += , has new lines , bullet point, inserting newline/bullet points if conditions not met end bulleted/blank lines along warnings. figured put

if ((bominputtextbox.text.contains(s4) && (bominputtextbox.text.contains(s5)))) 

it stop happening, doesn't. missing?

using (filestream filestream = new filestream(@"t:\\designer\\customcheck", filemode.open, fileaccess.read, fileshare.readwrite)) {     using (streamreader filereader = new streamreader(filestream)) {         while ((lineoftext = filereader.readline()) != null) {             regex regex4 = new regex("<ifcontainsand>(.*)</ifcontainsand>");             var v4 = regex4.match(lineoftext);             string s4 = v4.groups[1].tostring().toupper();              regex regexcontainsand = new regex("<ifcontainsand2>(.*)</ifcontainsand2>");             var v5 = regexcontainsand.match(lineoftext);             string s5 = v5.groups[1].tostring().toupper();              regex regex6 = new regex("<ifcontainsandwarningtext>(.*)</ifcontainsandwarningtext>");             var v6 = regex6.match(lineoftext);             string s6 = v6.groups[1].tostring().toupper();              if ((bominputtextbox.text.contains(s4) && (bominputtextbox.text.contains(s5)))) {                  warningstextbox.text +=                      (environment.newline + environment.newline + "•" + s6).tostring();             } 

the biggest problem never check see whether of regex-matches successful. when regex-match not successful, capture-groups empty string ""; whenever process lineoftext lacks <ifcontainsand>(.*)</ifcontainsand> , <ifcontainsand2>(.*)</ifcontainsand2>, if condition true (since all strings contain empty string).

to check whether match succeeded, can use the match.success property:

if (v4.success && bominputtextbox.text.contains(s4)     && v5.success && bominputtextbox.text.contains(s5)) { 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -