» String Functions by rdove |
|
(Login to remove green text ads)
This tutorial is going to cover string functions. There are several different string functions, but the scope of this tutorial is going to be limited to Len, Instr, Replace, and Split.
The first function, Len, will return the length of the characters in a string including any spaces within the string.
Example:
Code:
strVariable = "This is my string"
intCharsInString = Len(strVariable)
' intCharsInString = 17
Next is the Instr function. This function will return the placement number of the first occurance of a specified string within a string.
Example:
Code:
strVariable = "This is my string"
intCharsInString = Instr("s", strVariable)
' intCharsInString = 4
OUr next function is the Replace function. This function will replace a value in a string based on the string critera you give it.
Example:
Code:
strVariable = "This is my string"
strCharsReplaced = Instr(strVariable, "string", "tutorial")
' strCharsReplaced = This is my tutorial
And finally we have the Split function. The split function will separate a given string within a string value into an array.
Example:
Code:
strVariable = "This is my string"
strCharsSplit = Split(strVariable, " ")
' strCharsSplit(0) = This
' strCharsSplit(1) = is
' strCharsSplit(2) = my
' strCharsSplit(3) = string
I hope this gives you some insite on how you can manipulate and get information from strings using ASP and VBScript.
Tutorial by:
Ryan Wischmeyer, 2004
Indianapolis, IN
|
|