This tutorial will teach you all of the basic string functions
available in ASP using VBScript. I will keep things concise as
possible. The following is a list of the functions and an example of
each.
Asc();
Asc() will provide you with the ASCII character code of the character in the parentheses.
|
<% str1 = Asc("B") response.write str1 %> |
cStr();
cSrt() will convert a numeric value into a string.
|
<% int1 = 35 str1 = cStr(int1) %> |
inStr();
inStr() will locate the occurance of a character (or set of characters) in a string and output it's place.
|
<% str1 = "ABCDEF" str2 = inStr(str1,"BC") response.write str2 %> |
LCase();
LCase() will convert an entire string to lowercase.
|
<% str1 = "ABCDEF" str2 = LCase(str1) response.write str2 %> |
UCase();
UCase() will convert an entire string to uppercase.
|
<% str1 = "abcdef" str2 = UCase(str1) response.write str2 %> |
Trim();
Trim will remove all blank spaces from the beginning or end of a string.
|
<% str1 = " ABCDEF" str2 = Trim(str1) response.write str2 %> |
Len();
Len() will tell you the number of characters in a string.
|
<% str1 = "ABCDEF" str2 = Len(str1) response.write str2 %> |
Replace();
Replace() will replace a character (or set of characters) with another character (or set of characters).
|
<% str1 = "ABCDEF" str2 = Replace(str1,"CD","YZ") response.write str2 %> |
Split();
Split() will split a string into an array of values based on the character defined.
|
<% str1 = "ABC,DEF" str2 = Split(str1,",") response.write str2(0) response.write " " response.write str2(1) %> |
Left();
Left() will retrieve the number of characters specified from the left of the string.
|
<% str1 = "ABCDEF" str2 = Left(str1,3) response.write str2 %> |
Right();
Right() will retrieve the number of characters specified from the right of the string.
|
<% str1 = "ABCDEF" str2 = Right(str1,3) response.write str2 %> |
Mid();
Mid() will retrieve the number of characters specified from the middle of the string.
|
<% str1 = "ABCDEF" str2 = Mid(str1,3,2) response.write str2 %> |
That's it! Have fun playing with strings.


Reply