VB.NET String Functions

In this article we will learn how to use string functions in VB.NET.
  • 8127
Download Files:
 

In this article we will learn how to use string functions in VB.NET.

String Function - These are the following sting functions.

1. The  Len Function

The length function is used to find out the number of characters in any given string.

Syntax

Len(string)

2. The Mid function

The mid function is used to Return a substring containing a specified number of characters from a string.

Syntax

Mid (string, start[, length])

string - String expression from which characters are returned.

start - Long. Character position in string at which the part to be taken begins.

length - Length is Optional. Number of characters to return.

3. The Left Function

The Left function extract the left portion of a string.

Syntax

Left("string", n)

4. The Right Function

The Right function extract the right portion of a string.

Syntax

Right("string", n)

5. The Space Function

The space function is used to Return a string containing the specified number of blank spaces.

Syntax

Space (number)

6. The Replace Function

The replace function is used to replacing some text in a string with some other text.

Syntax

Replace( string, searchtext, replacetext )

7. The Trim function

The trim function trims the empty spaces on both side of the String.

Syntax

Trim ("String")

8. The Ltrim Function

The Ltrim function trims the empty spaces of the left portion of the string.

Syntax

Ltrim("string")

9. The Rtrim Function

The Rtrim function trims the empty spaces of the Right portion of the string.

Syntax

Rtrim("string")

10. The Ucase and the Lcase Functions

The Ucase function converts all the characters of a string to capital letters. On the other hand, the Lcase function converts all the characters of a string to small letters.

For Example - This example defines all the above function.

Module Module1

    Sub Main()

         Dim leng As String = Len(" Rohatash kumar")

        Console.WriteLine("length is :" & leng)

        Dim middle As String = Mid("Rohatash Kumar", 3, 4)

        Console.WriteLine("Mid is :" & middle)

        Dim leftf As String = Left("Rohatash Kumar", 3)

        Console.WriteLine("Left is:" & leftf)

        Dim rightr As String = Right("rohatash kumar", 6)

        Console.WriteLine("Right is :" & rightr)

        Dim spaces As String = Right("rohatash kumar", 7)

        Console.WriteLine("Space is :" & spaces)

        Dim replaces As String = Replace("rohatash kumar", "hat", "nmo")

        Console.WriteLine("Replace is :" & replaces)

        Dim trimt As String = Trim("   rohatash kumar  ")

        Console.WriteLine("Trim is :" & trimt)

        Dim ltriml As String = LTrim("    rohatash kumar     ")

        Console.WriteLine("ltrim is :" & ltriml)

        Dim rtrimr As String = RTrim("    rohatash kumar     ")

        Console.WriteLine("rtrim is :" & rtrimr)

        Dim ucaseu As String = UCase("rohatash kumar")

        Console.WriteLine("Ucase is :" & ucaseu)

        Dim lcasel As String = LCase("ROHATASH KUMAR")

        Console.WriteLine("Ucase is :" & lcasel)

    End Sub

End Module

 

Now run the console application.
 

c1.gif

Figure 1.

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.