常用转义字符

来源:互联网 发布:中信网络股权争夺战 编辑:程序博客网 时间:2024/06/01 09:41

编程的时候要注意特殊字符的问题,很多运行时出现的问题都是因为特殊字符的出现而引起的。

 

 

 

 

     

     

     

  •  

     

    javascript特殊字符

     

 

 

JScript 提供了一些特殊字符,允许在字符串中包括一些无法直接键入的字符。每个字符都以反斜杠开始。反斜杠是一个转义字符,表示 JScript 解释器下面的字符为特殊字符。

 

 

 

 

 

 

 

 

 

转义序列

 

字符

 

 

 

 

 

 

 

/b

 

退格

 

 

 

/f

 

走纸换页

 

 

 

/n

 

换行

 

 

 

/r

 

回车

 

 

 

/t

 

横向跳格 (Ctrl-I)

 

 

 

/'

 

单引号

 

 

 

/"

 

双引号

 

 

 

//

 

 

 

 

 

 

反斜杠

 

 

 

 

请注意,由于反斜杠本身用作转义符,因此不能直接在脚本中键入一个反斜杠。如果要产生一个反斜杠,必须一起键入两个反斜杠 (//)。

document.write('The image path is C://webstuff//mypage//gifs//garden.gif.');

document.write('The caption reads, "After the snow of /?. Grandma/'s house is covered."');

 

 

     

     

     

  •  

     

    html特殊字符

     

 

 

特别符号 &#?; (其中 ? 代表 ISO 8859-1 的编码) < < > > & & " " 注册商标TM ® N1.0+ 注册商标TM ® 著作权符号 © N1.0+ 著作权符号 ©

 

 

 

 

     

     

     

  •  

     

    java特殊字符

     

 

 

 

 

 

     

     

     

  •  

     

    sql特殊字符

     

 

 

 

 

 

     

     

     

  •  

     

    在程序中处理特殊字符(转义)

     

 

 

增删改中特殊字符的处理。

 

 

在textarea等html元素中字符串属于html的范围,要注意html的特殊字符;

 

 

信息提交到服务器之后,字符串进入java范畴,如果程序中要对字符串进行进一步的加工的话,就要注意java中的特殊字符串了;

 

 

如果字符串要组装到sql语句中,就要注意sql中的特殊字符串;例如:用statement来execute一个sql语句,使用preparedstatement就无需处理特殊字符。

 

 

相反的过程是,java中的字符串显示在网页上,则需要做一些html encode的工作了,如果java字符串还要通过javascript来显示,处理起来就更复杂了,例如:

 

《script》

additem2("《%=name%》");

function additem2(item){

var str="《input value='"+item+"' 》";

some.innerHTML = str;

《script》

 

 

<script>

 

 

如果字符串name中含有各种特殊字符,将会出现很多问题

常用特殊字符:

 

 

只要你认识了 HTML 标记,你便会知道特殊字符的用处。

 

 

HTML 原代码 显示结果 描述

&lt; < 小于号或显示标记

&gt; > 大于号或显示标记

&amp; & 可用于显示其它特殊字符

&quot; " 引号

&reg; ® 已注册

&copy; © 版权

&trade; ? 商标

&ensp; 半个空白位

&emsp; 一个空白位

&nbsp; 不断行的空白

 

 

■ ISO Latin-1 特殊字符 :

 

 

HTML 原代码 显示结果 描述

&AElig; Æ Uppercase AE diphthing

&Aacute; Á Uppercase A, acute accent

&Acirc; Â Uppercase A, circumflex accent

&Agrave; À Uppercase A, grave accent

&Aring; Å Uppercase A, ring

&Atilde; Ã Uppercase A, tilde

&Auml; Ä Uppercase A, dieresis or umlaut mark

&Ccedil; Ç Uppercase C, cedilla

&ETH; Ð Uppercase Eth, Icelandic

&Eacute; É Uppercase E, acute accent

&Ecirc; Ê Uppercase E, circumflex accent

&Egrave; È Uppercase E, grave accent

&Euml; Ë Uppercase E, dieresis or umlaut mark

&Iacute; Í Uppercase I, acute accent

&Icirc; Î Uppercase I, circumflex accent

&Igrave; Ì Uppercase I, grave accent

&Iuml; Ï Uppercase I, dieresis or umlaut mark

&Ntilde; Ñ Uppercase N, tilde

&Oacute; Ó Uppercase O, acute accent

&Ocirc; Ô Uppercase O, circumflex accent

&Ograve; Ò Uppercase O, grave accent

&Oslash; Ø Uppercase O, slash

&Otilde; Õ Uppercase O, tilde

&Ouml; Ö Uppercase O, dieresis or umlaut mark

&THORN; Þ Uppercase THORN, Icelandic

&Uacute; Ú Uppercase U, acute accent

&Ucirc; Û Uppercase U, circumflex accent

&Ugrave; Ù Uppercase u, grave accent

&Uuml; Ü Uppercase U, dieresis or umlaut mark

&Yacute; Ý Uppercase Y, acute accent

&aelig; æ Lowercase ae diphthing

&aacute; á Lowercase a, acute accent

&acirc; â Lowercase a, circumflex accent

&agrave; à Lowercase a, grave accent

&aring; å Lowercase a, ring

&atilde; ã Lowercase a, tilde

&auml; ä Lowercase a, dieresis or umlaut mark

&ccedil; ç Lowercase c, cedilla

&eth; ð Lowercase eth, Icelandic

&eacute; é Lowercase e, acute accent

&ecirc; ê Lowercase e, circumflex accent

&egrave; è Lowercase e, grave accent

&euml; ë Lowercase e, dieresis or umlaut mark

&iacute; í Lowercase i, acute accent

&icirc; î Lowercase i, circumflex accent

&igrave; ì Lowercase i, grave accent

&iuml; ï Lowercase i, dieresis or umlaut mark

&ntilde; ñ Lowercase n, tilde

&oacute; ó Lowercase o, acute accent

&ocirc; ô Lowercase o, circumflex accent

&ograve; ò Lowercase o, grave accent

&oslash; ø Lowercase o, slash

&otilde; õ Lowercase o, tilde

&ouml; ö Lowercase o, dieresis or umlaut mark

&szlig; ß Lowercase sharp s, German (sz ligature)

&thorn; þ Lowercase thorn, Icelandic

&uacute; ú Lowercase u, acute accent

&ucirc; û Lowercase u, circumflex accent

&ugrave; ù Lowercase u, grave accent

&uuml; ü Lowercase u, dieresis or umlaut mark

&yacute; ý Lowercase y, acute accent

&yuml; ÿ Lowercase y, dieresis or umlaut mark

 

 

 

 

Some characters like the < character, have a special meaning in HTML, and therefore cannot be used in the text.

有些字符,像<这类的,对HTML来说是有特殊意义的,所以这些字符是不允许在文本中使用的。

 

 

To display a less than sign (<) in HTML, we have to use a character entity.

要在HTML中显示(<)这个字符,我们就必须使用特殊字符。

 

 


 

 

 

Character Entities[特殊字符]

 

 

Some characters have a special meaning in HTML, like the less than sign (<) that defines the start of an HTML tag. If we want the browser to actually display these characters we must insert character entities in the HTML source.

有一些字符对HTML来讲是有特殊意义的,像小于符号(<)是用来定义HTML头标签的。如果我们想在浏览器中显示这类字符就必须在HTML代码中插入特殊字符。

 

 

A character entity has three parts: an ampersand (&), an entity name or a # and an entity number, and finally a semicolon (;).

一个特殊字符有三个部分:一个(&)符号,一个特殊符号名称或一个#加上一个特殊数字,最后是一个分号(;)。

 

 

To display a less than sign in an HTML document we must write: &lt; or &#60;

要显示小于符号就得在HTML中写:&lt; 或者&#60;

 

 

The advantage of using a name instead of a number is that a name is easier to remember. The disadvantage is that not all browsers support the newest entity names, while the support for entity numbers is very good in almost all browsers.

使用名称的好处是它比用数字来的方便记忆。但不是所有浏览器都支持最新的一些特殊字符,不像特殊字符那样很好的被所有浏览器做支持。

 

 

Note that the entities are case sensitive.

注意特殊字符需要注意大小写。

 

 

This example lets you experiment with character entities: Character Entities IE only

这个例子是让你来实验这些特殊字符的(只限IE浏览器)

 

 


 

 

 

Non-breaking Space[不换行空白]

 

 

The most common character entity in HTML is the non-breaking space.

在HTML中最普通的特殊字符就是不换行空白了。

 

 

Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML will remove 9 of them. To add spaces to your text, use the &nbsp; character entity.

一般HTML会给你的文本除去空白,如果你在文本中有10个空格那么HTML就会去掉其中的9个。想添加空格的话就得使用&nbsp; 字符。

 

 


 

 

 

The Most Common Character Entities[一些很常用的特殊字符]:

 

 

 

 

 

 

 

Result

 

Description

 

Entity Name

 

Entity Number

 

 

 

 

 

 

 

 

 

非换行空格

 

&nbsp;

 

&#160;

 

 

 

<

 

小于

 

&lt;

 

&#60;

 

 

 

>

 

大于

 

&gt;

 

&#62;

 

 

 

&

 

“&” 号

 

&amp;

 

&#38;

 

 

 

"

 

双引号

 

&quot;

 

&#34;

 

 

 

'

 

单引号

 

&apos; (IE不支持)

 

&#39;

 

 

Some Other Commonly Used Character Entities[其他一些]:

 

 

 

 

 

 

 

Result

 

Description

 

Entity Name

 

Entity Number

 

 

 

 

 

 

 

 

cent分

 

&cent;

 

&#162;

 

 

 

£

 

pound镑

 

&pound;

 

&#163;

 

 

 

¥

 

yen

 

&yen;

 

&#165;

 

 

 

§

 

section

 

&sect;

 

&#167;

 

 

 

©

 

copyright版权

 

&copy;

 

&#169;

 

 

 

®

 

registered 注册trademark

 

&reg;

 

&#174;

 

 

 

×

 

multiplication乘

 

 

 

 

 

 

&times;

 

 

 

 &#215;

 

 

 

 

 

 

 

 

 ÷

 

 division除

 

 &divide;

 

 

 

 &#247;

 

java特殊字符

转义序列 含义
/n 回车(/u000a)
/t 水平制表符(/u0009)
/b 空格(/u0008)
/r 换行(/u000d)
/f 换页(/u000c)
/' 单引号(/u0027)
/" 双引号(/u0022)
// 反斜杠(/u005c)
/ddd 三位八进制
/udddd 四位十六进制

sql特殊字符

SQL 的转义字符是:'(单引号)
例:select * from tbl where uyear='''06'
请注意其中红色背景的单引号,它即表示转义字符,如果我们省略,则整个语句会出错,转义字符不会输出,上例中 uyear 的实际条件值为 '06,而不是 ''06
为什么不能省略呢,假如我们省略,上句变成:select * from tbl where uyear=''06'
由于在 SQL 中单引号表示字符串的开始和结束符号,于是 SQL 解释器会认为语句中灰色背景的为字符串,其后的语句显然是个错误的语句,当然会报错,为了解决字符串的单引号问题,就出现了转义字符单。

原创粉丝点击