Mega Code Archive

 
Categories / VB.Net Tutorial / Data Type
 

Insert sub string by index

Option Strict On  Imports System  Class Tester      Public Shared Sub Main( )          Dim s1 As String = "abcd"          Dim s2 As String = "ABCD"          Dim s3 As String = "AAAAs "          s3 = s3 & "development"          Dim s5 As String = String.Copy(s2) '          Console.WriteLine("s5 copied from s2: {0}", s5)          Console.WriteLine("String s3 is {0} characters long. ",s5.Length)          Console.WriteLine("s3: {0}", s3)                    ' hold the location of provides as an integer          Dim location As Integer = s3.IndexOf("a")                    Dim s10 As String = s3.Insert(location, "u")          Console.WriteLine("s10: {0}", s10)      End Sub 'Main  End Class 'Tester s5 copied from s2: ABCD String s3 is 4 characters long. s3: AAAAs development Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negativ e and less than the size of the collection. Parameter name: startIndex at System.String.Insert(Int32 startIndex, String value) at Tester.Main()