Get or Return the Next Word after a Specific Word - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This is a tutorial on how to retrieve the next word after a certain word in Visual Basic .NET

get next word in visual basic .net

Let's say you have the following sentence: I love programming in visual basic. Then you like the program to find what the word after programming:

Add 2 textboxes to the form and a button:

return next word in visual basic 2010

The user will enter a word in the small textbox:

The code:

Imports System.Text.RegularExpressions
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim text As String = TextBox1.Text

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

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

            MsgBox(a.Groups(1).Value)
        Next
    End Sub
End Class

Result:

get the next word in visual basic 2008


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.