VB.Net String Pattern Matching
Hi,
I created a post here yesterday about copying/searching, now there's another part. I need to know when I perform a search how to invoke string pattern matching, if i was to type any specific data, i.e. A12345 or B54673 and so on. Can anyone help ?
[265 byte] By [
MarcD99] at [2007-12-25]
well you can make a method to do the pattern searching (I can't remember if it was myself that responded to your query) and "invoke" it (call it) when you need to call it say, from a button click or from a textchanged event from a textbox when the text length entered is to the length you expect the input to be.
example:
private function DoMatch(ByVal theString as String) as Boolean
'do match
end function
button click, just double click the button to make a click event
private Sub Button1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
if Me.DoMatch(Me.theTextBox.Text) = true then
'pattern has been matched successfully
end if
end sub
so you wish to do a search when the user presses the button? The above code does just that.
As you learn to develop more and more you will realize that having functions or sub methods of your own will be handy so you can call them from anywhere within your class instead of just a button click for example.
All you need to do is place the pattern matching code in the function and that's it
The function returns a boolean meaning true or false. So it depends how you are doing the pattern matching. If it's Regex, there is an IsMatch method which returns true or false if it found the match, so this is what you would use to return back true or false to the caller (the button) as shown in the code.
Otherwise to return the results you have to change the return type to whatever it is and change the way the code is being called on the button.
Any chance for seeing the code for pattern matching so we can try and implement this for you?