Pages

Saturday, 30 June 2012

String Functions of VB.NET(Part II)

Split Function: Split Function in VB.NET is used to break string using a specific delimiter. For eg. Split function break string into three part 'red', 'green' and 'blue' by using delimiter ',' as shown given below:-
Public Sub str_split()

        Dim str() = Split("red,green,blue", ",")
        For i = 0 To str.Length - 1
            MsgBox(str(i))
        Next
 
End Sub



InStr Function: InStr Function in VB.NET is used to find the starting position of a substring inside a string. For eg. InStr function return 15 as the substring 'VB.NET' is in the beginning of the string as shown given below:-

Public Sub InStrg()

        MsgBox("Starting index of VB.NET is:: " & InStr("Hello This Is VB.NET Code", "VB.NET"))

End Sub



LCase Function: LCase Function in VB.NET is used to returns a string after converting to lowercase. For eg. LCase function is used to converted 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' to 'abcdefghijklmnopqrstuvwxyz' lowercase alphabets as shown given below:-

Public Sub Lower_case()

        Dim Str As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        MsgBox("String in Lowercase is::" & LCase(Str))

End Sub



LTrim Function: LTrim Function in VB.NET is used to retruns a copy of a string without leading spaces. For eg. LTrim function remove the leading spaces from String such as '                  VB.NET' become 'VB.NET' as shown given below:-


Public Sub L_trim()

        MsgBox("String after removing leading spaces is:: " & LTrim("                  VB.NET"))

End Sub

Friday, 29 June 2012

String Functions of VB.NET(Part I)

Asc Function: Asc Function in VB.NET is used to return the ascii code for the first character in the string. For eg. Ascii code for A,B,C are 65, 66, 67 respectively as shown given below:-

Public Sub ascii()

        MsgBox("Character Code of A :: " & Asc("A"))
        MsgBox("Character Code of B :: " & Asc("B"))
        MsgBox("Character Code of C :: " & Asc("C"))
      
End Sub 


Chr Function: Chr Function in VB.NET is used to return the character for the specified Ascii value. For eg. character code for 65 to 90 represent the Capital A to Z  as shown given below:-


Public Sub chr_code()

        For i = 65 To 90
            MsgBox("Character " & i & " is :: " & Chr(i))
        Next
 
End Sub


GetChar Function: GetChar Function in VB.NET is used to return the character of the string from the specified index. For eg. character W, T, A return index 1, 9, 12  as shown given below:-

Public Sub GetCharacter()

        Dim Str As String = "Welcome To All"
        For i = 1 To 14
            MsgBox("Character at the index value " & i & " is :: " & GetChar(Str, i))
        Next
 
End Sub