Home >>VB.Net Built-in Functions >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 :
Return Value :
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
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.