ASP in the interpretation of double quotes, single quotes and & number _asp basis

Source: Internet
Author: User
Many of the early-learning Friends of ASP may have lost their way in double quotes, single quotes and & numbers. The key is not to understand the meaning of three types of symbols, of course, can not well grasp their use. Here are my views on the three types of symbols, the technology is not fine, it is inevitable that there is negligence, I would like to ask you to give more advice.

1, double quotes ""

In double quotes, an ASP can be any character, string, or HTML code.
Like what


<%response.write ("Cnbruce here")%><%response.write ("<b>cnbruce here</b>")%>


The resulting page effects are: Default text and bold text "Cnbruce here"

Now think about it, what if I want to add a color effect to the output page text?

1, general text color This writes: <font color= "#0000ff" >cnbruce</font>

2,response.write writing is like this: Response.Write ("Enter the displayed content")

3, if you want to place the above hyperlink code in Response.Write, do you find that the double quotes in the Write method and the double quotes in the color form a nested effect.
Bound to form Response.Write ("<font color=" #0000ff ">cnbruce</font>")

4, debugging results are not optimistic, because the color of the front quotes and write before the quotation marks match, the content is <font color=; The same color's back quotation marks match the write's back quote, which reads: >cnbruce</font>。 The end result: The middle #0000ff was alone.

5, so for the result to be correct, you can put #0000ff as a string inside the double quotes, and then the string and the previous string <font color=and back string >cnbruce</font>The middle connection is used & No.

The final results are as follows:


<%
Response.Write ("<font color=" & "#0000ff" & ">cnbruce</font>")
%>



2, single quotes '

As with the language class, the quotation marks that continue to be placed in double quotes can be in single quotes.

So the above statement Response.Write ("<font color=" #0000ff ">cnbruce</font>")#0000ff can change its double quotes into single quotes:
Response.Write ("<font color= ' #0000ff ' >cnbruce</font>"), and this is done equally correctly.

3, connection character & number

The main role of & in ASP is to connect, including: string-string, string-variable, variable-variable, such as a mixed connection.

For example, the following example:



<%
Mycolor= "#0000ff"
Response.Write ("<font color= '" &mycolor& "' >" & "Cnbruce" & "</font>")
%>



One of the great things to note is that double quotes are used in color single quotes ~! You may be burnt, look slowly.

1, now is the definition of a variable mycolor, according to the principle, the variable placed in the Response.Write does not need to add double quotes, because the addition of a double citation is a string, not a variable AH.

2, so Response.Write if you want to output variables you can write directly: Response.Write (MyColor)

3, however, now. Our variables must be put in double quotes (such as the above program is placed in a single citation), then how to write the specific Response.Write?

4, the key to the wording: the ASP will continue to add the variables around the "&Include, you can put in the Response.Write quotation marks, the effect is: Response.Write ("&mycolor&")

5, the Analysis of Response.Write ("" &mycolor& "), in fact, is the first empty string connection MyColor variable after the connection of a string.

6, so, now for the above ASP the whole example should be understood.

continue to strengthen and deepen



<%
Mycolor= "#0000ff"
Response.Write ("<font color= '" &mycolor& "' >" & MyColor & "</font>")
%>



This contains the strings, variables, and the use of the variables in quotation marks. I believe you will be able to understand it.

Finally, you can also use HTML and ASP to mix.



<%mycolor= "#0000ff"%>
<font color=<%=mycolor%>><%=mycolor%></td>



This is not difficult, easy to understand:)

Well, that's all I think about.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.