IT KNOWLEDGE

IT KNOWLEDGE
BC

Saturday, May 24, 2014

How to find a word after specific one word (VB.Net)

Sometime programmers need a method to find the word after one specific word in one specific develop program such as VB.Net, C#, Java.... To reply this, I wrote the sample one application using VB.Net to find word after one specific word which input in textbox as below:

Application Design

No Control Type Name Text
1 Form1 FormWordAfterWord Get Word After Word
2 Textbox1 TextboxWord
3 Textbox2 TextboxFind
4 Button1 ButtonFind Find

  • As you see sample above, we input text in TextBoxWord "Visual Basic is my favourite" and we want to find one word which located after word "my" in TextBoxFind and the message box show that "The word after word : my is favourite" which is right to our goal.

 Code
Imports System.Text.RegularExpressions
Public Class FormWordAfterWord

    Private Sub ButtonFind_Click(sender As Object, e As EventArgs) Handles ButtonFind.Click

        Dim text As String = TextBoxWord.Text



        Dim word As String = "\b" & TextBoxFind.Text & "\b\s+(\w+)"



        For Each a As Match In Regex.Matches(text, word, RegexOptions.IgnoreCase)



            MessageBox.Show("The word after word: " & TextBoxFind.Text & "  is  " & a.Groups(1).Value)

        Next
    End Sub
End Class













Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: itech-9999

0 comments: