9. VbScript | Len, Left, Right Functions

Remember to try the codes yourself for practice.

So today I will be talking about the Len, Left, and Right functions that can be used to manipulate string data.

↑ Counts the number of characters in your string.

↑ Cuts off from the left after reading # of characters.

↑ Cuts off from the right after reading # of characters.

For example:

or

Output:

Capture

↑ The Len function outputted to a message box the total number of characters that is included in the string Hello there, including the space in between.

Let me show you an example showing how the Left function works. Let’s say that we only want the word Hello to show up in the message box from the string. You can count from the left the number of characters Hello takes up, which is 5:

Output:

Capture2

Similarly, we can use the Right function to select the characters from the right. Let’s say we want to output the word there in an input box. So we select 5 character from the right:

Output:

Capture3

A better example that shows you how versatile these functions are is when you want to switch text from two strings to make it output something different. Let’s start with two strings:

Let’s say you want a message box to say that cats are funny:

Output:

Capture4

Let’s say you want a message box to say that babies are cute:

Output:

Capture5


What's Your Opinion?