Try something like this:
If File.ReadLines(txtFilePath).Any(Function(line) txtInput.TrimEnd.EndsWith(line.TrimEnd, StringComparison.CurrentCultureIgnoreCase)) Then
. . .
End If
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Newbie question:
I am new to using Visual Studio (I was decent with MS Access) and I'm trying to validate user entries into a textbox, and there are a number of conditions, but I'm only really struggling with the last part.
I need to ensure that the entry ends with any of the strings that are stored in a .txt file (which supervisors can edit at any time to keep up with future updates)
Can I compare against the file or do I need to somehow open it first? Do I need to store them in an array before I can compare against them? How do I write my code to use the file/array like a wildcard?
I assume the comparison part could look similar to this:
If (txtInput Like "*[<.txtfile>]" = True) Then
Try something like this:
If File.ReadLines(txtFilePath).Any(Function(line) txtInput.TrimEnd.EndsWith(line.TrimEnd, StringComparison.CurrentCultureIgnoreCase)) Then
. . .
End If
Sadness. I was wrong. I am still getting stumped, and now I realize that it has to match exactly with the entire portion of the txtInput(user entry) that follows "00", which is another layer of complexity I wasn't expecting.
i.e. with LEAD in the text file, "...00LEAD" would be accepted, but "...00SLEAD", "...00LEADS", "...00EAD", and "..00LEA" would all fail.
I figured it out eventually, and I was thinking about it wrong. I needed to trim my entry data down to just the part I needed to compare, then treat each line in the text file as an .equals test against the trimmed entry as a whole.