+92 332 4229 857 99ProjectIdeas@Gmail.com

String.Substring function (Vb.net)


String Substring function
String.Substring() function takes a part of string from the input string. This function has two overloads.
First: Substring(starting index)
Second: Substring(starting index , length)
Example1 demonstrates first overload and Example2 demonstrates the second overload.
System.String is the library for this function.
 
Example1
Dim str1 As String = "Saad Bin Saulat"
Dim str2 As String = String.Empty
str2 = str1.Substring(3)
MsgBox(str2)
Result
The message box will contain "d Bin Saulat" as a substring of str1 beacuse it is mentioned to take a substring starting from index number 3.First a substring "d Bin Saulat" is stored in str2 and after that it is displayed in the message box.

Example2
Dim str1 As String = "Saad Bin Saulat"
Dim str2 As String = String.Empty
str2 = str1.Substring(0, 3)
MsgBox(str2)
Result
The message box will contain "Saa" as a substring of str1.First a substring "Saa" is stored in str2 and after that it is displayed in the message box.


Related articles

0 comments: