How to remove the first occurrence of a word from a string in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        Dim s As String = "c c++ vb java python vb java"
        
		Dim word As String = "vb"
		
        Dim index As Integer = s.IndexOf(word)
		
        s = If((index < 0), s, s.Remove(index, word.Length + 1))
			
        Console.Write(s)
    End Sub
End Class
	
	

' run:
'	
' c c++ java python vb java
'	
	

 



answered Apr 16, 2022 by avibootz
...