Thursday, September 24, 2009

ASP String Function List

ASP String Function List


Strings, or variables that take letters and numbers, are used in just about every ASP script written. Here are some functions that allow you to work with them.

Asc
Returns the ascii code of a given character.To use the Asc function, you feed in a character and it returns the numeric ascii ID of that character.

CodeNum = Asc(LetterInput)

cStr
Converts an integer or other numeric value into a string.
YearText = cStr(YearInt)

InStr
Located the first occurrence of a character or characters within a string.

LCase
Makes an entire string lower case.

Left
Gets the leftmost X characters from a string

Len
Tells you the number of characters in a string.

Mid
Extracts a group of characters from the center of a string.

Replace
Replaces a character or characters within a string with a new character or characters.

Right
Gets the rightmost X characters from a string

Split
Break a string up into bits based on spaces, periods, or other characters.

Trim
Removes any spaces from the beginning or end of a string.

UCase
Makes an entire string upper case.

ASP DateAdd

DateAdd(code, count, date)

Code comes from the table below and indicates what unit of time you are adding to your initial date:

Code Time Span
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second


Count is the number of those units you will be adding - 3 days, 4 hours, 1 month. This can be negative if you want to go backwards in time.

Date is the starting date you wish to begin with.

So to take today's date and figure out what the date was one month ago, you would use

DateAdd("m", -1, Now())