TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET LTrim and RTrim Functions

Use the LTrim and RTrim Functions, which remove spaces from the left and right.
LTrim, RTrim. LTrim and RTrim are available in VB.NET. What does the LTrim function do? The L here stands for Left—the left trim method removes spaces from the left of the String passed to it. RTrim meanwhile removes from the right side of String data.Strings
LTrim. In this example, we declare a String literal with three spaces before the first letter character. Then, we pass the variable that points to that String literal to the LTrim function. The string value returned has no leading spaces on it.
VB.NET program that uses LTrim function Module Module1 Sub Main() Dim value1 As String = " The Dev Codes" Dim value2 As String = LTrim(value1) Console.WriteLine("[{0}]", value2) End Sub End Module Output [The Dev Codes]
How is the LTrim function implemented? To investigate, I opened the Microsoft.VisualBasic.dll file with IL Disassembler. I found that, internally, LTrim calls TrimStart. So you can think of LTrim as a wrapper method for TrimStart.

But: It would be more efficient to simply call TrimStart yourself. This is possible without too much trouble.

IL Disassembler TutorialTrimEnd, TrimStart
RTrim. Let's get started with RTrim. A String literal with several trailing spaces is declared and the value1 variable points to it. When this variable is passed to RTrim, another String is returned.

Output: We can see that there are no trailing spaces remaining on the right side of the string value.

Note: The original String literal is unchanged, but changes are made to another copy which is displayed.

VB.NET program that calls RTrim Module Module1 Sub Main() Dim value1 As String = "The Dev Codes " Dim value2 As String = RTrim(value1) Console.WriteLine("[{0}]", value2) End Sub End Module Output [The Dev Codes]
Internally, RTrim simply calls TrimEnd on the String type. TrimEnd is a form of Trim that only acts on the trailing (right-side) characters. It would be possible, and usually preferable, to directly call TrimEnd.
Summary. We looked at the LTrim function in the VB.NET language and saw both its effect and its implementation in the .NET Framework. This function may be convenient and familiar. But it simply invokes TrimStart.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf