How do I find parts of a word in a string using an array for the keywords?
I need to run a program on computers but exclude certin users based off of the computer name. The computers naming convention is xx-yyy-Lastname. The Lastname sometimes has the users initials added to it so I need to see if I can find only part of it.
IF the computers name is DT-WAR-BISMITH and my array contains {"Walter", "Trevor", "Smith"} how would I flag this as an exclusion?

Dim computer1() As String = Split(My.Computer.Name, "-")
        Dim style As String = computer1(2)
        Dim Exclude() As String = {"Walter", "Trevor", "Smith"}
        If Exclude.Contains(style, StringComparer.OrdinalIgnoreCase) Then
            MessageBox.Show("Found on list")
        End If
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim strComNAme As String = "DT-WAR-BISMITH"
        Dim strEx As String = "SMITH"
        If strComNAme.Contains(strEx) Then
            Debug.Print("Found")
        End If
    End Sub

O.K. this code works. Contains is case sensitive and I think you want to find the person name within th wcomputer name and not vise versa.

Thanks, So I modified this to look like;

Dim Exclude as String() = {"Smith", "Walter", "Roberts"}
    Dim compname As String = My.Computer.Name
            Dim strex As String
            For i = 0 To Exclude.Length - 1
                strex = Exclude(i)
                If compname.ToUpper.Contains(strex.ToUpper) Then
                    End 'ends program if name is found
                End If
            Next

Thank you.

Edited 2 Years Ago by Spyderbane

This question has already been answered. Start a new discussion instead.