One of things that newbies find difficult when trying to learn ASP is the way code is tructured and what all those special characters are there for.
In this short post we are going to see the most common special characters we can find in an ASP page:
- <% ... %>
- <%= ... %>
The ampersand or "&" is used in ASP to concatenate strings.
Combining strings is easy:
strName1 = "Hello"
strName2 = "world!"
strName = strName1 & " " & strName2
That was easy.
The apostrophe " ' " is used for commenting code. In any case, the code after the apostrophe is never executed.
The underscore "_" is used to span the code on multiple lines. I must say I never use this special character in my code, but there you are. If you want your code to span on multiple lines, use the underscore:
response.write ("This is a long string," &_
" and we want to keep it visible so that " &_
"it won' hide on the right side of the page!")
This one is quite obscure: we use the semicolon ":" when we need to put multiple lines of code on just one line. Isn't it crazy? Well, if you ever need to do it, now you know how.
strOne = "1" : strTwo = "2" : strThree = "3"
We all know that with ASP we have objects because basically it is an Object Oriented Programming Language. Well, objects have methods and in order to specify an object method we use a period ".".
The object in fact is followed by its method, separated by a dot like in "myObject.Method".
Percentage is used to delimit ASP code. This is easy:
Equal and percentage
... ASP code goes here ...
This is used as a write shortcut: when we need to print something we can use <%= instead of response.write().
strName = "Hello!"
Ok everyone. That's all for today.