An object-oriented programming language developed by Microsoft that can be used in .NET.
I think this is fine
If AddFolderTextBoxX.Text.Trim().IndexOfAny(Path.GetInvalidFileNameChars()) > -1 Then
MessageBox.Show("bad!!!")
End If
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
I've written this to check if a path name does not include invalid chars which is 2 loop inside each other:
For Each MyChar As Char In AddFolderTextBoxX.Text.Trim
For Each BadChar As Char In Path.GetInvalidFileNameChars()
If MyChar = BadChar Then
MessageBox.Show("bad!!!"
Exit Sub
End If
Next
Next
Can this be improved in any way to prevent inner loops? Or this is just fine?
Also which one is preferred?
If MyChar = BadChar Then...
or
If String.Equals(MyChar, BadChar, StringComparison.OrdinalIgnoreCase) = True Then
Thanks :)
An object-oriented programming language developed by Microsoft that can be used in .NET.
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Answer accepted by question author
I think this is fine
If AddFolderTextBoxX.Text.Trim().IndexOfAny(Path.GetInvalidFileNameChars()) > -1 Then
MessageBox.Show("bad!!!")
End If