Salad UN

To Taste The Salad Of Life.

« CSS+XHTML网页标准规范化命名参考Asp跨站共享ACCESS数据库和数据库链接优化 »

JavaScript从Html页面中提取所有汉字

[ At 2008-9-20 By Ash   0 comments ]

使用JavaScript从Html页面中提取所有汉字
<SCRIPT LANGUAGE="vbScript">
dim str
str="怎样从一个Html页面中提取所有汉字呢?不能有其它Html代码。"
alert FilterChinese(str)

function FilterChinese(strInput)
dim result:result=""
dim tempStr
for i=1 to len(strInput)
tempStr=mid(strInput,i,1)
if left(escape(tempStr),2)="%u" then
result=result & tempStr
end if
next
FilterChinese=result
end function

 </SCRIPT>


if asc(tempStr)>255 then

用正则表达式的方法
<SCRIPT LANGUAGE="vbScript">
dim str
str="怎样从一个Html页面中提取所有汉字呢?不能有其它Html代码。"
alert RegExpTest("[\u4e00-\u9fa5]",str)

 

Function RegExpTest(patrn, strng)
   Dim regEx, Match, Matches   ' 建立变量。
   Set regEx = New RegExp   ' 建立正则表达式。
   regEx.Pattern = patrn   ' 设置模式。
   regEx.IgnoreCase = True   ' 设置是否区分大小写。
   regEx.Global = True   ' 设置全局替换。
   Set Matches = regEx.Execute(strng)   ' 执行搜索。
   For Each Match in Matches   ' 遍历 Matches 集合。
      RetStr = RetStr  &  Match.Value
   Next
   RegExpTest = RetStr
End Function

 </SCRIPT>
 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense

Copyright 2008 www.s-un.cn. Some Rights Reserved.