Answered Best way to compare a string format?

CraftMuch

New member
Joined
Jul 30, 2014
Messages
2
Programming Experience
3-5
Say I have a string format "people(<no.people>)" and I want to compare another string "people(5)". If the string fits the format it will return true, otherwise it will return false.
"people(5)" will return true
"people(5243)" will return true
"people(5)5" will return false
"people" will return false...
I am aware of how to get content within the brackets, just not how to verify the rest of the string.
Thanks
 
Hi.

You can just use the 'Like' operator.

Here's an example console program

Module Module1
    Sub Main()
        Console.Write("Enter text to test : ")
        Dim myText As String = Console.ReadLine
        If myText Like "People(*)" Then
            Console.WriteLine("True - String Format Matched")
        Else
            Console.WriteLine("False - String Didn't Match Format")
        End If
        Console.ReadKey()
    End Sub
End Module
 
Not quite sure how to mark this as solved?

When you start the thread, you should set the Prefix to Question. When the issue is resolved, you can edit the first post and change the Prefix to Answered. Not sure if you have to have a particular number of posts before you can edit though. Should look that up.
 
Back
Top