Sunday, September 24, 2006

Manipulating Strings in Classic ASP with Left, Mid, and Right

String manipulation is straightforward in classic ASP using the Left(), Mid(), and Right() functions.

Left() returns the number of specified characters from the left side of a string. It's formatted as Left(string, length). Example:
Left("one two three four five",3)
would return "one" (the left 3 characters).

Mid is a little more complex. It returns the number of characters specified from the starting point specified. It's formatted as Mid(string, start, length). Note that a length variable is optional; if omitted, Mid it will get the remaining character in the string from the starting point (just like a Right()). Example:
Mid("one two three four five",4,3)
would return "two" (start at character 4 and get the next 3 characters.

Right() return the number of characters specified from the right side of the string. It's formatted as Right(string, length.)xample:
Right("one two three four five",4)
would return "five" (the right 4 characters).

By using Left(), Mid(), and Right() in combination with Instr(), you should be able to get any peice of any string you need.

No comments: