首页
微信
安卓
接口
移动
前端
专题
文档库
工具
网址
§
ITPOW
>>
文档
>>
ASP
>>
ASP应用
英语单词拼写检查(连载三)
作者:chilleen 来源:
ITPOW
日期:2006-1-15
来源:
ITPOW
(www.itpow.com)
现将代码转换成VBScript语言。
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>英文单词拼写检查</title> </head> <body> <div> <a href="http://www.itpow.com/" target="_blank">ITPOW www.itpow.com 专业探讨【ASP、JavaScript、XHTML+CSS、SQL Server】</a> <hr> </div> <div>请输入<b>unlocd</b>: <input type="text" id="key" name="key" size="20"><input type="button" value="检查" onclick="vbscript:Analyse(document.getElementById('key').value)"></div> <script type="text/vbscript" language="vbscript"> <!-- '字典类 class CDic private prvWord, prvCode private sub class_initialize() prvWord= "" prvCode = 0 end sub public property let word(v) prvWord = v prvCode = GetCode(prvWord) end property public property get word() word = prvWord end property public property get code() code = prvCode end property end class '获得单词编码 function GetCode(word) dim code, i code = 0 for i=1 to Len(word) code = code + Asc(Mid(word, i, 1)) - 96 next GetCode = code end function '字典对象 function IniDic() dim i for i=0 to UBound(dic) set dic(i) = new CDic next end function ' 还未被调用 function TerminateDic() dim i for i=0 to UBound(dic) set dic(i) = nothing next end function dim dic(9) call IniDic() dic(0).word = "unlike" dic(1).word = "unload" dic(2).word = "unlock" dic(3).word = "unlucky" dic(4).word = "unnecessary" dic(5).word = "unofficial" dic(6).word = "unpleasant" dic(7).word = "unpopular" dic(8).word = "unprofitable" dic(9).word = "unqualified" '分析输入值 function Analyse(key) dim i for i=0 to UBound(dic) if GetSimilarLevel(dic(i).word, LCase(key)) = 1 then infoStr = infoStr & vbcrlf & dic(i).word end if next if infoStr <> "" then alert("您要找的是不是:" & infoStr) else alert("无建议词") end if end function '判断source与key的相似度 '返回类型:数字类型。 '返回值:0-相似度很低,1-相似度较高属建议单词,2-完全相同 '不忽略大小写比较 '如果要执行忽略大小写的比较,请事先对source和key进行大小写统一 function GetSimilarLevel(source, key) dim sLen, kLen sLen = Len(source) kLen = Len(key) '首先确认长度 if sLen <> kLen and _ sLen <> kLen+1 and _ sLen <> kLen-1 then GetSimilarLevel = 0 exit function end if '逐个字母比较 dim i, j, breakPoint, similarLevel i = 1 j = 1 breakPoint = false '断点,比较时发现了字母不同 similarLevel = 1 '相似度 do while (i<=sLen and j<=kLen) if Mid(source, i, 1) = Mid(key, j, 1) then '字母相同,比较下一字母 i = i + 1 j = j + 1 elseif not breakPoint then '第一次发现字母不同 '结合字符串长度判断是多了一个字母、少了一个字母、错了一个字母 '然后再移动相应的比较位置 breakPoint = true if sLen > kLen then i = i + 1 elseif sLen < kLen then j = j + 1 else i = i + 1 j = j + 1 end if else '第二次发现字母不同,不符合建议单词的定义,结束比较 similarLevel = 0 exit do end if loop if not breakPoint and sLen=kLen then '单词长度相等,比较完了也未产生断点 similarLevel = 2 end if GetSimilarLevel = similarLevel end function --> </script> </body> </html>
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
连载三结束
相关文章
创建于2005年
渝ICP备05010272号-1
电邮:
cftea@126.com
即将跳转...