Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the Trim() function

VB.Net program to demonstrate the Trim() function

Write a VB.Net program to demonstrate the Trim() function

In which to remove the blank space on both the left and right sides, the Trim() function is used.

Syntax :

Trim(str)

Parameters :

  • Str: the string you specified may contain a blank space on the left or right side.

Return Value :

  • After removing blank space on both the left and right sides, the Trim() function will return a string.

Program :

Below is the source code for demonstrating the Trim() function. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim str1 As String = " I love india "
        Dim str2 As String = ""
        str2 = Trim(str1)
        Console.WriteLine("Trimmed string: #{0}#", str2)
    End Sub
End Module
	
Output:
Trimmed string: #I love india#

Explanation:

We created a Module1 module in the program above that contains the Main() method. We have created two variables str1 and str2 in the Main() method, where variable str1 is initialized with " I love india " and variable str2 with a blank string is initialized.

str2 = Trim(str1)

We used the Trim() function in the above code, which returns the string after removing space on both the left and right sides. Then, on the console screen, we printed the string.


No Sidebar ads