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
 
Joined
Mar 18, 2014
Messages
18
Location
Devon, UK
Programming Experience
3-5
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
 

CraftMuch

New member
Joined
Jul 30, 2014
Messages
2
Programming Experience
3-5
Thanks works perfectly!
Not quite sure how to mark this as solved? So if any mods see this, it's solved. :biggrin:
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,295
Location
Sydney, Australia
Programming Experience
10+
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.
 
Top Bottom