Check if String Contains, Replacing Sub Strings
The String.Contains method is used when you want to check whether a specified substring occurs within the string.
It returns True if the value parameter occurs within the string, otherwise it returns False.
The String.Replace method is used when you want to replace all occurences of a specified string with another specified string.
It returns new string that is same as the current string except that all instances of oldValue are replaced with newValue.
If oldValue is not found this method returns the same string unchanged.
It returns True if the value parameter occurs within the string, otherwise it returns False.
The String.Replace method is used when you want to replace all occurences of a specified string with another specified string.
It returns new string that is same as the current string except that all instances of oldValue are replaced with newValue.
If oldValue is not found this method returns the same string unchanged.
1
2
3
4
5
6
7
| Dim OriginalString As String = "Hello User" Dim ModifiedString As String = String .Empty; If OriginalString.Contains( "Hello" ) Then ModifiedString = OriginalString.Replace( "Hello" , "Good Bye" ) Console.WriteLine(ModifiedString) ' = Good Bye User" End If |