How to remove a given word from a string in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function removeWord(ByVal str As String, ByVal word As String) As String
        If str.Contains(word) Then
            Dim tmp As String = word & " "
            str = str.Replace(tmp, "")
            tmp = " " & word
            str = str.Replace(tmp, "")
        End If

        Return str
    End Function

	Public Shared Sub Main()
		Dim str As String = "vb.net c# java c c++ python rust go"
        Dim word As String = "rust"
		
        str = removeWord(str, word)
		
        Console.Write(str)
    End Sub
End Class





' run:
'
' vb.net c# java c c++ python go
'

 



answered Nov 19, 2022 by avibootz
...