Home / .NET / String Manipulation function in VB
string

String Manipulation function in VB

In this, we will learn how to use some of the string manipulation function such as Len, Right, Left, Mid, Trim, Ltrim, Rtrim, Ucase, Lcase, Instr, Val, Str  ,Chr and Asc.

i)The  Len

The length function returns an integer value which is the length of a phrase or a sentence, including the empty spaces. The format is Len (“Phrase”)

For example, Len (VisualBasic) = 11 and Len (welcome to VB tutorial) = 22

ii) The Right

The Right function extracts the right portion of a phrase. The format is Right (“Phrase”, n) Where n is the starting position from the right of the phrase where the portion of the phrase is going to be extracted. For example,

Right(“Visual Basic”, 4) = asic

iii)The Left

The Left$ function extract the left portion of a phrase. The format is Left(“Phrase”, n) Where n is the starting position from the left of the phase where the portion of the phrase is going to be extracted. For example,

Left (“Visual Basic”, 4) = Visu

iv) The Ltrim

The Ltrim function trims the empty spaces of the left portion of the phrase. The format is Ltrim(“Phrase”) .For example, Ltrim (“ Visual Basic”, 4)= Visual basic

v) The Rtrim

The Rtrim function trims the empty spaces of the right portion of the phrase. The format is Rtrim(“Phrase”) .For example, Rtrim (“Visual Basic ”, 4) = Visual basic

  

vi) The Trim

The Ttrim function trims the empty spaces on both side of the phrase. The format is Trim(“Phrase”) .For example, Trim (“ Visual Basic ”) = Visual basic

vii) The Mid

The Mid function extracts a substring from the original phrase or string. It takes the following format: Mid(phrase, position, n)

Where position is the starting position of the phrase from which the extraction process will start and n is the number of characters to be extracted. For example, Mid(“Visual Basic”, 3, 6) = ual Bas

viii) The InStr function

The InStr function looks for a phrase that is embedded within the original phrase and returns the starting position of the embedded phrase. The format is Instr (n, original phase, embedded phrase)

Where n is the position where the Instr function will begin to look for the embedded phrase. For example Instr(1, “Visual Basic”,” Basic”)=8

ix) The Ucase and the Lcase

The Ucase function converts all the characters of a string to capital letters. On the other hand, the Lcase function converts all the characters of a string to small letters. For example,

Ucase(“Visual Basic”) =VISUAL BASiC

Lcase(“Visual Basic”) =visual basic

x) The Str and Val

The Str is the function that converts a number to a string while the Val function converts a string to a number. The two functions are important when we need to perform mathematical operations.

xi) The Chr and the Asc

The Chr function returns the string that corresponds to an ASCII code while the Asc function converts an ASCII character or symbol to the corresponding ASCII code. ASCII stands for “American Standard Code for Information Interchange”. Altogether there are 255 ASCII codes and as many ASCII characters. Some of the characters may not be displayed as they may represent some actions such as the pressing of a key or produce a beep sound.

The format of the Chr function is Chr(charcode) and the format of the Asc function is Asc(Character)

The following are some examples:

Chr(65)=A, Chr(122)=z, Chr(37)=% , Asc(“B”)=66, Asc(“&”)=38

About Helpservices

About This site (allhelpservices.com) is dedicated to helping other bloggers learn the skills of blogging, wordpress, education, technology, social media sharing , SEO, Electronics, Earn Money From Blogging, Web hosting and web share their own experiences and promote the blogging medium. We started Allhelpservices in August 2015 mainly because we wanted to keep a record of what we wear learning from development and because we wanted to connect with other learners.

Check Also

ASP.NET and PHP

What is the difference between ASP.NET and PHP ?

ASP.NET and PHP both are server side technologies; PHP is open source and ASP.NET own ...

Leave a Reply