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 LSet and RSet Functions

Use the LSet and RSet String Functions to add padding or truncate a string.
LSet, RSet. LSet and RSet are string padding Functions. They allow you to pad the right (LSet) and left (RSet) sides of a string with spaces.Strings
Here we look at these VB.NET functions in more detail. Usually in VB.NET we prefer PadRight and PadLeft on strings—these are more common because they are used in C#.
First example. Let's begin by looking at the LSet and RSet in a program. We see that the string returned by LSet is padded to 20 characters total by adding spaces to the right.

And: The string returned by RSet, meanwhile, is padded to 20 characters total by adding spaces to the left.

VB.NET program that uses LSet and RSet functions Module Module1 Sub Main() Console.WriteLine("[{0}]", LSet("test", 20)) Console.WriteLine("[{0}]", RSet("test", 20)) Console.WriteLine("[{0}]", LSet("test", 2)) Console.WriteLine("[{0}]", RSet("test", 2)) End Sub End Module Output [test ] [ test] [te] [te]
Internals. The implementation of LSet and RSet in the Microsoft.VisualBasic.dll is simple. LSet internally calls PadRight. RSet internally calls PadLeft.

However: LSet and RSet are more complex than just the pad methods. The implementation has a path that calls Substring.

Internals, substring. These functions call Substring if you specify that the string be reduced below its current length. So they either pad or truncate.Substring

Tip: It is often a better idea just to use PadRight, PadLeft and Substring directly. This is more standard practice in the .NET Framework.

PadLeft, PadRight
A summary. We looked at LSet and RSet. We peeked inside the Visual Basic implementation. These functions truncate or pad strings without any If-statements added directly to your code.If Then
© 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