Remove Spaces: Trim, LTrim, and RTrim Functions in VB.NET

Today, i will teach you how to remove spaces using Trim, LTrim, and RTrim functions of VB.NET. These 3 functions removes spaces. Trim functions get rid of spaces in both left and right space. LTrim funcrion remove spaces from the left side of a text. And the RTrim functions remove spaces from the right side of a text. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add three Buttons named Button1 and labeled it as "LTrim", Button2 and labeled it as "Trim", and Button3 and labeled it as "RTrim". Add two textbox named textbox1 for inputting your desired text and textbox2 for the output of trimming your input. You must design your interface like this: design 3. In your button1 as LTrim button, put this code below. LTrim function remove the leading spaces or the left spaces before the text.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. TextBox2.Text = LTrim(TextBox1.Text)
  3. End Sub
Output: output 4. In your button2 as Trim button, put this code below. Trim function remove the leading spaces or the left spaces before the text and right spaces after the text.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. TextBox2.Text = Trim(TextBox1.Text)
  3. End Sub
Output: output 5. In your button3 as RTrim button, put this code below. RTrim function remove the trailing spaces or the right spaces after the text.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. TextBox2.Text = Trim(TextBox1.Text)
  3. End Sub
Output: output Hope this helps! :) Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Visit and like my page on Facebook at: https://www.facebook.com/BermzISware Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Add new comment