Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the functions of Pinyin and UrlEncode in Js

Shulou Source: shulou.com Published: 2022-06-02 12:41:30 10月04日 Update

Editor to share with you how to achieve the functions of Pinyin and UrlEncode in Js. I hope you will get something after reading this article. Let's discuss it together.

Urlencoding, which is often written in vb, is easy to implement UrlEncode, as well as using the

Code in .NET / Develop/read_article.ASP?id=13846 "> http://www.csdn.net/Develop/read_article.asp?id=13846"

The code in vbs can be easily rewritten to realize the pinyin of some Chinese characters.

But because some people need to write entirely in Javascript, and Javascript defaults to Unicode

So we need a conversion library of Unicode and GB.

For the conversion libraries and UrlEncode and getSpell functions of Unicode and GB, please download

Idea.com/user/qswh/qswhU2GB.js "> http://www.blueidea.com/user/qswh/qswhU2GB.js

Var qswhU2GB= []; / / the corresponding tables of Unicode and GB, briefly

Var qswhSpell= []; / / comparison table of Pinyin

Function UrlEncode (str) {

Var iMagnec strSpecial= "!" # $% &'() * +, /:; @ [] ^ `{|} ~% "

For (iTunes 0x4e00) {

C=qswhU2GB [str.charCodeAt (I)-0x4e00]

Ret+= "%" + c.slice (0Magne2) + "%" + c.slice (- 2)

}

Else {

C=str.charAt (I)

If (cased = "")

Ret+= "+"

Else if (strSpecial.indexOf (c)! =-1)

Ret+= "%" + str.charCodeAt (I) .toString (16)

Else

Ret+=c

}

}

Return ret

}

Function getSpell (str,sp) {

Var iMagnec ret = ""

If (sp==null) sp= ""

For (iTunes 0x4e00) {

C=parseInt (qswhU2GB [str.charCodeAt (I)-0x4e00], 16)

If (c0witt sp 2) if (qswhSpell [t] 0) ret+= qswhSpell [t-1] + sp

}

}

}

Return ret.substr (0ret. Copyright sp.length)

}

After reading this article, I believe you have a certain understanding of "how to achieve the functions of Pinyin and UrlEncode in Js". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Pinyin functions codes articles functions finished comparison tables commonly used more knowledge industry information information channels parts channels Chinese characters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi NVidia Shulou Tech Info Huawei