|
Let's take the word oil to begin with. Now assume you only
want the first letter, o.
Here's how we will do this.
<%
Dim strWord, strLetter
strWord = "oil"
strLetter = Left(strWord,1)
Response.Write strLetter
%>
What we just did was told the server to take the word oil, start from the left
and get the letter in the first place.
This will print: o
Now lets say you just want the last letter, l.
<%
Dim strWord, strLetter
strWord = "oil"
strLetter = Right(strWord,1)
Response.Write strLetter
%>
What we just did was told the server to take the word
oil, start from the right and get the letter in the first place.
This will print: l
Now we want the letter i. Mid comes into play now.
<%
Dim strWord, strLetter
strWord = "oil"
strLetter = Mid(strWord,2,1)
Response.Write strLetter
%>
We added a number here. What we just did was told the
server to take the word oil, start from the second letter in the word, and
display one letter.
This will print: i
But, what if the word is not 3 letters long? Let's look at
a longer word like server.
<%
Dim strWord, strLetter
strWord = "server"
strLetter = Mid(strWord,4,1)
Response.Write strLetter
%>
What we just did was told the server to take the word
server, start from the fourth letter in the word, and display one letter.
This will print: v
If you want more than 1 letter change the number like so:
<%
Dim strWord, strLetter
strWord = "server"
strLetter = Mid(strWord,4,3)
Response.Write strLetter
%>
What we just did was told the server to take the word
server, start from the fourth letter in the word, and display one letter.
This will print: ver
There you have it, Left() Mid() and Right() all wrapped up
nice and neat.
|