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.
Len(string)=#
↑ Counts the number of characters in your string.
Left(string, #)= reads left to right
↑ Cuts off from the left after reading # of characters.
Right(string, #)= reads right to left
↑ Cuts off from the right after reading # of characters.
For example:
msgbox Len("Hello there")
or
a="Hello there" msgbox Len(a)
Output:
↑ 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:
a="Hello there" msgbox Left(a, 5)
Output:
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:
a="Hello there" msgbox right(a, 5)
Output:
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:
a="Cats are cute" b="Babies are funny"
Let’s say you want a message box to say that cats are funny:
a="Cats are cute" b="Babies are funny" msgbox Left(a,9)+Right(b,5)
Output:
Let’s say you want a message box to say that babies are cute:
a="Cats are cute" b="Babies are funny" msgbox Left(b,11)+Right(a,4)
Output: