VB.Net program to demonstrate the Trim() function

Here, we are going to demonstrate the Trim() function in VB.Net.
Submitted by Nidhi, on December 04, 2020

The Trim() function is used to remove the blank space from both the left and right sides.




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

Return Value:

The Trim() function will return a string after removing blank space from both the left and right sides.

Program/Source Code:

The source code to demonstrate the Trim() function is given below. The given program is compiled and executed successfully.

'VB.Net program to demonstrate the Trim() function.

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


Trimmed string: #I love india#
Press any key to continue . . .


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

str2 = Trim(str1)

In the above code, we used the Trim() function that will return the string after removing space from both the left and right sides. Then we printed the string on the console screen.

VB.Net Basic Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.