推薦:ASP連接11種數據庫語法總結經常使用到有關數據庫的操作。包括連接代碼、SQL命令等等,又不曾刻意去記憶它們(我本人是不願意去記這東東),所以常常在用到的時候又去查書本,翻來翻去。一些比較少用的數據庫還不一定能順
這次更新了一下自已所用的博客程序,將生成靜態文件時的文件名用文章標題的拼音,這就涉及到如何將文字轉成拼音了,在網上大概的看了看,千篇一律的那個函數,應該只可以在GB2312下正常,也沒有做太多考慮,這就拿出了曾在無憂系統的源碼裡看到過的一段用上了。
來看看下面的函數,加入少量註釋:
這是一個自定義特殊詞語的一個函數
| 以下為引用的內容: Function getEnglish(ByVal Str) getEnglish = Str getEnglish = Replace(getEnglish, 中國, china ) getEnglish = Replace(getEnglish, 策劃, plan ) getEnglish = Replace(getEnglish, 免費, free ) getEnglish = Replace(getEnglish, 介紹, intro ) getEnglish = Replace(getEnglish, 技巧, skill ) getEnglish = Replace(getEnglish, 生活, life ) getEnglish = Replace(getEnglish, 活動, activity ) getEnglish = Replace(getEnglish, 工具, tool ) getEnglish = Replace(getEnglish, 聯盟, union ) getEnglish = Replace(getEnglish, 註冊, register ) getEnglish = Replace(getEnglish, 經驗, experience ) getEnglish = Replace(getEnglish, 翻譯, translate ) getEnglish = Replace(getEnglish, 項目, item ) getEnglish = Replace(getEnglish, 網站, web-site ) getEnglish = Replace(getEnglish, 英語, english ) getEnglish = Replace(getEnglish, 英文, english ) getEnglish = Replace(getEnglish, 雅虎, yahoo ) getEnglish = Replace(getEnglish, 新浪, sina ) getEnglish = Replace(getEnglish, 支付寶, alipay ) getEnglish = Replace(getEnglish, 交易, trade ) getEnglish = Replace(getEnglish, 網店, b2c ) getEnglish = Replace(getEnglish, 升級, update ) getEnglish = Replace(getEnglish, 雜誌, magazine ) getEnglish = Replace(getEnglish, 空間, space ) getEnglish = Replace(getEnglish, 愛情, love ) getEnglish = Replace(getEnglish, 朋友, friend ) getEnglish = Replace(getEnglish, 友情, friend ) getEnglish = Replace(getEnglish, 鏈接, like ) getEnglish = Replace(getEnglish, 標籤, label ) getEnglish = Replace(getEnglish, 運行, running ) getEnglish = Replace(getEnglish, 管理, manager ) getEnglish = Replace(getEnglish, 管理, manage ) getEnglish = Replace(getEnglish, 頁面, page ) getEnglish = Replace(getEnglish, 模板, template ) getEnglish = Replace(getEnglish, 遊戲, game ) getEnglish = Replace(getEnglish, 論壇, forum ) getEnglish = Replace(getEnglish, 新聞, news ) getEnglish = Replace(getEnglish, 音樂, music ) getEnglish = Replace(getEnglish, 幫助, help ) getEnglish = Replace(getEnglish, 優化, optimize ) getEnglish = Replace(getEnglish, 軟件, soft ) getEnglish = Replace(getEnglish, 教程, tech ) getEnglish = Replace(getEnglish, 下載, download ) getEnglish = Replace(getEnglish, 搜索, search ) getEnglish = Replace(getEnglish, 引擎, engine ) getEnglish = Replace(getEnglish, 蜘蛛, spider ) getEnglish = Replace(getEnglish, 日誌, log ) getEnglish = Replace(getEnglish, 博客, blog ) getEnglish = Replace(getEnglish, 百度, baidu ) getEnglish = Replace(getEnglish, 谷歌, google ) getEnglish = Replace(getEnglish, 郵箱, mailbox ) getEnglish = Replace(getEnglish, 郵件, mail ) getEnglish = Replace(getEnglish, 域名, domain ) getEnglish = Replace(getEnglish, 測試, test) getEnglish = Replace(getEnglish, 演示, demo ) getEnglish = Replace(getEnglish, 音樂, music ) getEnglish = Replace(getEnglish, 笑話, joke ) getEnglish = Replace(getEnglish, 產品, product ) getEnglish = Replace(getEnglish, 留言, message ) getEnglish = Replace(getEnglish, 反饋, freedback ) getEnglish = Replace(getEnglish, 評論, comment ) getEnglish = Replace(getEnglish, 推薦, commend ) getEnglish = Replace(getEnglish, 共享, share ) getEnglish = Replace(getEnglish, 資源, resource ) getEnglish = Replace(getEnglish, 插件, plugins ) getEnglish = Replace(getEnglish, 本本, notebook ) getEnglish = Replace(getEnglish, 電腦, computer ) getEnglish = Replace(getEnglish, 系統, system ) getEnglish = Replace(getEnglish, 學校, school ) getEnglish = Replace(getEnglish, 無憂, 5u ) getEnglish = Replace(getEnglish, 工作, job ) getEnglish = Replace(getEnglish, 信息, info ) getEnglish = Replace(getEnglish, 娛樂, ent ) getEnglish = Replace(getEnglish, 汽車, car ) getEnglish = Replace(getEnglish, 手機, mobile ) getEnglish = Replace(getEnglish, 網絡, network ) getEnglish = Replace(getEnglish, 老闆, boss ) getEnglish = Replace(getEnglish, 狗, dog ) getEnglish = Replace(getEnglish, 電視, tv ) getEnglish = Replace(getEnglish, 電影, movie ) End Function |
然後就是最關鍵的函數pinyin(byval chinese) 他將中文轉換到拼音
| 以下為引用的內容: function pinyin(byval chinese) chinese = replace(chinese, /, ): chinese = replace(chinese, /, ) chinese = replace(chinese, *, ): chinese = replace(chinese, ], ) chinese = replace(chinese, [, ): chinese = replace(chinese, }, ) chinese = replace(chinese, {, ): chinese = replace(chinese, ', ) chinese = getEnglish(chinese) '在這裡使用getEnglish先將特殊詞語轉換 dim pinyinstr, istr, iIsCn, IsCn dim pinyinconn, rs, i, x '在這裡打開拼音庫 '你也可以將拼音庫的併入你的程序數據庫裡. on error resume next set pinyinconn = server.createobject(Adodb.connection) pinyinconn.open Provider=Microsoft.Jet.OLEdb.4.0;Data Source= & server.mappath(pinyin.Asp) if err then pinyin = : set pinyinconn = nothing: exit function IsCn = true for i = 1 to len(chinese) iIsCn = IsCn ' 獲取上次是不是中文的值 istr = Mid(chinese, i, 1) x = Asc(istr) if (x >= 65 and x <= 90) or (x >= 97 and x <= 122) or (x >= 48 and x <= 57) or istr = then IsCn = false ' 這些是英文,數字(保留字符),不改動 if istr = then istr = - else set rs = pinyinconn.execute(select Top 1 [pinyin] From [pinyin] Where [content] like '% & istr & %';) if not rs.eof then istr = lcase(rs(0)): IsCn = true ' 中文 else IsCn = false if istr = then istr = - else istr = ' 將空格轉換成-,如果是其他字符則清除 end if rs.close: set rs = nothing end if if iIsCn = IsCn then pinyinstr = pinyinstr & istr else pinyinstr = pinyinstr & - & istr pinyinstr = replace(pinyinstr, --, -) pinyinstr = replace(pinyinstr, __, _) next if right(pinyinstr, 1) = - then pinyinstr = left(pinyinstr, len(pinyinstr) - 1) if right(pinyinstr, 1) = _ then pinyinstr = left(pinyinstr, len(pinyinstr) - 1) if left(pinyinstr, 1) = - then pinyinstr = right(pinyinstr, len(pinyinstr) - 1) if left(pinyinstr, 1) = _ then pinyinstr = right(pinyinstr, len(pinyinstr) - 1) pinyinconn.close set pinyinconn = nothing pinyin = trim(pinyinstr) end Function |
使用方法:
| 以下為引用的內容: response.write pinyin(中國你好,歡迎來到中國!) |
這種方法,轉換成的拼音格式文件名非常友好,對SEO方面有要求的小程們,可以試試的。
分享:asp簡介和五大內置對象目次1. ASP基礎2. ASP的五大對象3. Request對象4. Response對象5. Server對象6. Application對象7. Session對象1. ASP基礎Microsoft Active Server Pages,即讀者朋友們所稱的