SUBSTRING METHOD IN VB.NET

SUBSTRING METHOD IN VB.NET
The Left function returns a portion of the string, the number of characters defined by the Number argument.The VB .NET equivalent of Left or Right is the SubString method Here’s an example:
Substring or Left(String, Number)
=================================================================================
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n As String
Dim m As String = "welcome to anuchathannoor.blogspot.com"
n = Microsoft.VisualBasic.Left(m, 4) 'frist 4 letter
MsgBox(n)
n = Microsoft.VisualBasic.Right(m, 4) 'LAST 4 letter
MsgBox(n)
n = m.Substring(7, 4) 'NEXT 4 LETTER FROM 7TH POSSISION
MsgBox(n)
n = m.Substring(8) 'BALANCE LETTER FROM 8TH POSSISION
MsgBox(n)

End Sub
==================================================================================
It’s a little like the Left and Right functions, except Mid can extract a substring (a string within a string) from anywhere within a string. Left and Right are limited to getting characters on one end of a string or the other. The VB .NET Substring
method does all of these things.The Mid function works like this:
==================================================================================
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(Mid("ANURAJS", 2, 4))
End Sub
==================================================================================

No comments: