2010.02.22(2)——javascript charCodeAt()方法和fromCharCode()方法

2010.02.22(2)——javascript charCodeAt()方法和fromCharCode()方法
1.charCodeAt()方法
   返回一个字符的Unicode值,该字符位于指定索引位置
   用法:
stringObject.charCodeAt(index)


   实例:
   在字符串"Hello world!"中我们将返回位置1的字符的Unicode值

  
var str="Hello world!"
   document.write(str.charCodeAt(1))


   输出结果为:

  
101 


2.fromCharCode()方法
   将Unicode码转换为对应的字符并返回为字符串
   用法:
String.fromCharCode(numX,numX,...,numX)

  
   实例:
   我们将通过Unicode码输出"HELLO"和”ABC“:

  
document.write(String.fromCharCode(72,69,76,76,79))
   document.write(String.fromCharCode(65,66,67))



   输出结果为:

  
HELLO
   ABC 

你可能感兴趣的:(JavaScript,java)