The function of Pinyin and Urlencode (using GB and Unicode comparison table)

zhaozj2021-02-16  53

Urlencoding, often written with VB, easy to implement urlencode, and using http://www.9cbs.net/develop/read_article.asp?id=13846 to easily rewrite into VBS to achieve some Chinese characters, but because some people Need to write completely with JavaScript, while JavaScript is unicode unicode, you need a Unicode and GB convert library.

Unicode and GB convert libraries and urlencode and getspell functions, please download http://www.blueidea.com/user/qswh/qswhu2gb.jsvar qswhu2GB = []; // Unicode and GB correspondence table, slightly var qswhspell = [ ]; // Pinyin control table, slight function urlencode (str) {var i, c, ret = ", strspecial ="! # $% & '() * , / :; <=>? @ [/] ^ `{|} ~%"; For (i = 0; i = 0x4e00) {c = qswhu2GB [str.charcodeat (i) -0x4e00]; RET = "%" C.SLICE (0, 2) "%" C.SLICE (-2);} else {c = str.Charat (i); if (c == "" RET = " "; Else IF (STRSPECIAL.INDEXOF (C)! = - 1) RET = "%" Str.Charcodeat (i) .tostring (16); Else Ret = C;}} Return Ret;

Function GetSpell (STR, SP) {VAR I, C, T, RET = ""; if (sp == NULL) sp = ""; for (i = 0; i = 0x4e00) {c = parseint (qswhu2GB [str.charcodeat (i) -0x4e00], 16); if (c <55290) {for (t = qswhspell.length-1; t> 0; T = T-2) IF (qswhspell [t] <= c) Break; if (t> 0) RET = qswhspell [T-1] sp;}}} Return Ret.Substr (0, Ret.Length-SP .length);} SP is separator, examples are as follows