Did you find this useful?
Socialize it today.

ASP Special Characters

Thursday, September 06, 2012

tags ASP

All programming languages have special and/or reserved characters that are used for specific purposes. ASP is no different. In this tutorial, we will cover the most common special characters that are used in ASP development.

Declaring ASP Code

An ASP page is simply a collection of HTML and ASP code. To distinguish the ASP code on the page, the code must be within a <script> element, or between the percent (<% %>) characters.

'My ASP Code Goes Here!

Response.Write Shortcut

The percentage equal (%=) sequence allows for quick access to the Response.Write() method that is used to write information to the web browser. This shortcut can be used to quickly print strings for example.

<%="Hello World!"%>

Using Objects

ASP supports the use of objects and their associated properties and methods. You use the period (.) to separate the object from its properties and methods.


String Concatenation

Strings can be easily combined with the ampersand (&) character. The ampersand joins one or more strings. Here is an example on how to concatenate two string.

Dim aString
aString = "First String"
aString = myString & " Second String"

The results are as follows...

First String Second String


The apostrophe (') is used to prevent the ASP engine from executing the text that follows the character. In ASP, there is only the single line comment, unlike other programming languages or even HTML where you can comment out a block of statements. Here is an example of the apostrophe.

' This is a comment.

Spanning Multiple Lines

It is common to have some of your statements not fit on a single line. Rather than tabbing to the right, you may prefer to break up the code statement. You can use the underscore (_) to instruct the ASP engine that your line of code continues to the next line. This allows you to have a single ASP statement span multiple lines.

Response.Write("This is a very long string "&_
"that I rather break up into multiple lines "&_
"so I can read it easier.")

The results are as follows...

This is a very long string that I rather break up into multiple lines so I can read it easier.

Multiple ASP Statements on One Line

There may be some occassions where you prefer to have fewer lines of code. The colon (:) can be used to have multiple lines of ASP code onto a single line.

Dim x : Dim y : Dim z
x=10 : y=2 : z=x+y

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.

Recommended Books & Training Resources

Beginning ASP Databases Sams Teach Yourself Active Server Pages 3.0 in 21 Days ASP In A Nutshell