C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Argument 1: This is the index in the original string where we want to place the new substring. With 4, we place after the fourth char.
Argument 2: This is the new string we want to place inside of the original string. It will be found in the result.
VB.NET program that uses Insert function on String
Module Module1
Sub Main()
Dim value As String = "the cat"
Console.WriteLine("INITIAL: {0}", value)
' Use Insert at an index.
Dim result As String = value.Insert(4, "soft ")
Console.WriteLine("INSERT: {0}", result)
End Sub
End Module
Output
INITIAL: the cat
INSERT: the soft cat
Insert: The first argument to Insert here is the index we received from IndexOf.
And: The index is the position of the start of the substring "cat" in the original string.
VB.NET program that uses Insert with IndexOf
Module Module1
Sub Main()
Dim value As String = "the soft cat"
Console.WriteLine("INITIAL: {0}", value)
' Use Insert with IndexOf.
Dim index As Integer = value.IndexOf("cat")
Dim result As String = value.Insert(index, "orange ")
Console.WriteLine("INSERT: {0}", result)
End Sub
End Module
Output
INITIAL: the soft cat
INSERT: the soft orange cat