Computers & ProgrammingASPBackend Development

ASP Special Characters

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 the <script> element, or between the percent (<% %>) characters.

<body>
    <%
    'My ASP Code Goes Here!
    %>
</body>

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!"%>
<%=Date()%>

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.

myObj.methodName()

String Concatenation

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

<%
Dim aString
aString = "First String"
aString = myString & " Second String"
Response.Write(myString)
%>

The results are as follows…

First String Second String

Comments

The apostrophe (') is used to prevent the ASP engine from executing the text that follows the character. In ASP, there is only a 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 occasions 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
%>

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top