Asp JavaScript 教程 - Lesson 02 Escape Characters

转载 2006年06月24日 13:16:00

Escape Characters

Not Out of Place:

The instruction of Escape Characters in Lesson 02 seems out of place. But it's not. Escape Characters are an integral part of using JavaScript in ASP. Lesson 02 is exactly the right spot for escape characters. Without escape characters, you will struggle to write effective ASP scripts in JavaScript. Sorry.

Get Started:

Below is the ASP Script for Lesson 02.

Response.Write("<FONT COLOR=/"red/">/"Hello World/"</FONT><BR>/r")
Response.Write("<FONT COLOR='blue'>'Hello World'</FONT><BR>/r")

Click Here to run the script in a new window.

Remember in Lesson 01 how the entire HTML output was on one line. The escape characters allow us to add carriage returns.

Below is the HTML source code as seen on the client side.

<FONT COLOR="red">"Hello World"</FONT><BR>
<FONT COLOR='blue'>'Hello World'</FONT><BR>

Escape Return:

I've reprinted a single line of ASP script below. Look at the "/r" at the end of the line.

Response.Write("<FONT COLOR=/"red/">/"Hello World/"</FONT><BR>/r")

The "/r" is a special character representing a carriage return. It's how I got the separate lines of HTML output on ...well... separate lines. That's vitally important on larger applications and larger pages. I said it before, but I'll say it again. Trust me; you can't find bugs if you can't even make heads or tails of what you're putting out to the client.

Escape Quote:

There's something else you should notice. See how I put the backslash underneath some of the quotation marks. What would happen if I remove the backslashes? Let's try the following line of code.

Response.Write("<FONT COLOR="red">"Hello World"</FONT><BR>")

I would get an error code, which is copied below.

Microsoft JScript compilation error '800a03ee' 

Expected ')' 

/asp/Section01/Script02.asp, line 4 

Response.Write("<FONT COLOR="red">"Hello World"</FONT><BR>")

No Escape:

What if I don't like Escape Characters? Do I have to use them?

You can limp along without them. Consider the line below.

Response.Write("<FONT COLOR='blue'>'Hello World'</FONT><BR>")

/b Backspace
/cD Control-D
/f Form Feed
/n New Line
/r Carriage Return
/t Tab
/xnn Hexadecimal
/0nn ASCII Escape Characters
/' Single Quote
/" Double Quote
// Backslash

You can interchange single quotes with double quotes. It's awkward, in my opinion. But it works. Even with that said, HTML aesthetics are the least important reason to use Escape Characters.

The List:

A far more important reason to utilize escape characters is that it allows us to output a whole list of special characters.

Most Important:

But the most important reason to use Escape Characters (at least for any sophisticated application) is for your database connection. (Database connections get their own lesson later on.) Compare the two Connection Strings below.

var Connection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("//TopLevelVirtualFolder") + "//database//myDatabase.mdb;"

Dim Connection;
Connection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/TopLevelVirtualFolder") & "/database/myDatabase.mdb;"

Next Up:

There's another little tool we absolutely must have to write ASP JavaScript. And that's in lesson 03.


转载地址: 最近半年来身边开发的朋友越来越多的提到OkHttp,上谷歌百度一下,确实OkHttp成了时下最火的...
  • mao1059568684
  • mao1059568684
  • 2017年06月14日 19:36
  • 380


最近项目中用js的escape函数,要求原生的也用,网络搜索了半天没有结果,只好对着java的实现自己实现一个,放在这里希望有需要的小伙伴能用到。 个人对oc不是很熟悉,如果你有更好的实现,也别喷我...
  • liyeo
  • liyeo
  • 2015年06月23日 17:56
  • 994


使用escape是为了使所有编码都转换成统一的编码格式(Unicode), 如GBK编码的"中国", 与UTF8编码的"中国",它们的escape返回值都是一样的,所以代码具有通用性,且escape在...
  • woshisap
  • woshisap
  • 2013年12月20日 23:03
  • 2429

Java Escape加密解密

package com.venustech.tsoc.cupid.risk.util; import; import; im...
  • csdn1125
  • csdn1125
  • 2016年07月07日 14:01
  • 515


  • wangyizhi58
  • wangyizhi58
  • 2013年04月18日 17:06
  • 1271


  • qq_30740239
  • qq_30740239
  • 2016年10月09日 17:28
  • 995


很久没有用过java SAX的原始解析方式了,今天yin
  • icefireforest
  • icefireforest
  • 2014年07月16日 19:43
  • 836


+(NSString *)escape:(NSString *)str { NSArray *hex = [NSArray arrayWithObjects: ...
  • u013457022
  • u013457022
  • 2016年03月07日 23:27
  • 939


在很多论坛中看到关于VBscript和javascript到底应该使用哪个,哪个比较好的问题?  今天我来谈谈我的看法:  服务器端:  大家知道ASP支持这两中脚本语言,也就是在服...
  • Chair_
  • Chair_
  • 2014年10月31日 15:30
  • 1408

SQL 模糊查询 和 escape

escape的主要用途 当你想查询_,%特殊字符时,请用escape Select ename from emp where ename like ‘%s_%’ escape ...
  • rqrtqqpqi5
  • rqrtqqpqi5
  • 2016年07月16日 17:21
  • 410
您举报文章:Asp JavaScript 教程 - Lesson 02 Escape Characters