Code: Select all
; msgbox, % HexEscape("爱尔兰之狐" )
HexEscape(cnStr) ; "爱尔兰之狐" --> "\u7231\u5C14\u5170\u4E4B\u72D0"
{ ; from tmplinshi
OldFormat := A_FormatInteger
SetFormat, Integer, Hex
Loop, Parse, cnStr
out .= "\u" . SubStr( Asc(A_LoopField), 3 )
SetFormat, Integer, %OldFormat%
Return out
} ; http://ahkscript.org/boards/viewtopic.php?f=28&t=3897&sid=7cfc6b20e192d838e1c127b6da9f275c
; msgbox, % Unescape("\u7231\u5c14\u5170\u4e4b\u72d0")
UnHexEscape(uXXXX) ; in: "\u7231\u5c14\u5170\u4e4b\u72d0" out: "爱尔兰之狐" 注意:不能参杂其他字符
{ ; by RobertL
Loop, Parse, uXXXX, u, \
retStr .= Chr("0x" . A_LoopField) ;为字符串添加16进制前缀。字符=Chr(编码)。
return retStr
} ; http://ahkscript.org/boards/viewtopic.php?f=28&t=3897&sid=7cfc6b20e192d838e1c127b6da9f275c
MsgBox % JavaEscapedToUnicode("\u7231\u5c14\u5170\u4e4b\u72d0")
JavaEscapedToUnicode(s)
{ ; by tmplinshi
i := 1
while j := RegExMatch(s, "\\u[A-Fa-f0-9]{2,4}", m, i)
e .= SubStr(s, i, j-i) Chr("0x" SubStr(m, 3)), i := j + StrLen(m)
return e . SubStr(s, i)
} ; For AutoHotkey Basic and AutoHotkey_L ANSI, note that anything higher than \u007F may be incorrect if your system code page is not 1252 (i.e. US English).
; http://www.autohotkey.com/board/topic/63263-unicode-escaped-string-convert-u00/?p=398749
MsgBox % UnescapeUnicodeHexNotation("\u7231\u5c14\u5170\u4e4b\u72d0")
UnescapeUnicodeHexNotation(Unicodehex)
{
pos := 0
While pos := RegExMatch(Unicodehex, "\\u(?P<hex>[0-9a-fA-F]{2,4})", m_, pos+1)
{
VarSetCapacity(LE, 2, "UShort")
NumPut("0x" . m_hex, LE)
s := StrGet(&LE, 2) ; StrGet(&sData,"cp0")
StringReplace, Unicodehex, Unicodehex, %m_%, %s%, All
} ; [参考] http://ahk8.com/thread-1927.html?highlight=%E7%BF%BB%E8%AF%91#post_11658
Return Unicodehex
}
uri := "file:///D:/03%20Schreiben/01_Texte/15%20%E2%80%93%20Encyclop%C3%A4dien/Encyclopedia%20of%20Sociology.pdf"
; http://www.javzoo.com/cn/search/"+encodeURIComponent($('#search-input').val().replace(/\./g,'-'));
; MSScriptControl.ScriptControlClass WIN7下无效的类 解决办法: 运行 Regsvr32 msscript.ocx http://bbs.csdn.net/topics/310013545
encodeURIComponent(Uri){
oSC := ComObjCreate("ScriptControl"), oSC.Language := "JScript"
Script := "var Encoded = encodeURIComponent(""" . Uri . """)"
oSC.ExecuteStatement(Script)
Return, oSC.Eval("Encoded") ; encodeURIComponent()不编码的字符: ~!*()'
} ; 另一个encodeURI() 不编码的字符: ~!@#@{content}*()=:/,;?+'
msgbox % decodeURIComponent( uri )
decodeURIComponent(Uri){
oSC := ComObjCreate("ScriptControl"), oSC.Language := "JScript"
Script := "var Decoded = decodeURIComponent(""" . Uri . """)"
oSC.ExecuteStatement(Script)
Return, oSC.Eval("Decoded")
} ; ScriptControl版本 http://www.autohotkey.com/board/topic/75...ntry492181
msgbox % decodeURI( uri )
decodeURI( u )
{
( obj := ComObjCreate( "ScriptControl" ) ).Language := "JScript"
return obj.Eval( "decodeURI(`""" u `""");" )
} ; https://gist.github.com/TLMcode/390a627237c500678adf
decodeURI64bit( u )
{
( obj:=ComObjCreate("HTMLfile") ).write("<p>/</p><script>document.getElementsByTagName(""p"")[0].innerHTML=decodeURI(`""" u `""");</script>")
return obj.getElementsByTagName("p")[0].innerHTML
} ; https://gist.github.com/TLMcode/6c4e12da47e3df270274
; modified from jackieku's code (http://www.autohotkey.com/forum/post-310959.html#310959)
; 中文字符集编码Unicode ,gb2312 , cp936 ,GBK,GB18030 http://www.cnblogs.com/finallyliuyu/archive/2013/05/10/3071023.html
UriEncode(Uri, Enc = "UTF-8")
{
StrPutVar(Uri, Var, Enc)
f := A_FormatInteger
SetFormat, IntegerFast, H
Loop
{
Code := NumGet(Var, A_Index - 1, "UChar")
If (!Code)
Break
If (Code >= 0x30 && Code <= 0x39 ; 0-9
|| Code >= 0x41 && Code <= 0x5A ; A-Z
|| Code >= 0x61 && Code <= 0x7A) ; a-z
Res .= Chr(Code)
Else
Res .= "%" . SubStr(Code + 0x100, -1)
}
SetFormat, IntegerFast, %f%
Return, Res
} ; UriEncode("伊東エリ", "cp20936") ; GB2312 cp10002是MAC机上的big5编码,950是ANSI的标准
; MsgBox, % UriDecode(Uri, "cp20936")
UriDecode(Uri, Enc = "UTF-8") ; CP936对应的就是GBK,有21791个汉字,GB2312-1980,CP20936它含ASCII字符,日文假名(字母),俄文字母,7千左右的中文字。
{
Pos := 1
Loop
{
Pos := RegExMatch(Uri, "i)(?:%[\da-f]{2})+", Code, Pos++)
If (Pos = 0)
Break
VarSetCapacity(Var, StrLen(Code) // 3, 0)
StringTrimLeft, Code, Code, 1
Loop, Parse, Code, `%
NumPut("0x" . A_LoopField, Var, A_Index - 1, "UChar")
StringReplace, Uri, Uri, `%%Code%, % StrGet(&Var, Enc), All
}
Return, Uri
}
StrPutVar(Str, ByRef Var, Enc = "")
{
Len := StrPut(Str, Enc) * (Enc = "UTF-16" || Enc = "CP1200" ? 2 : 1)
VarSetCapacity(Var, Len, 0)
Return, StrPut(Str, &Var, Enc),VarSetCapacity(var,-1)
}
; Decimal NCR编码 HTML、XML等语言的转义序列(numeric character reference(NCR))
; 数字取值为目标字符的 Unicode code point;以「&#」开头的后接十进制数字,以「&#x」开头的后接十六进制数字。
; 如中国等同与"中国" Asc("中")=20013 另一种形式%26%2320013%3B
EscapeDecimalNCR(text, encodeuri=0)
{
Loop, Parse, text
if encodeuri = hex
{
OldFormat := A_FormatInteger
SetFormat, Integer, Hex
out .= "&#x" . SubStr( Asc(A_LoopField), 3 ) . ";"
SetFormat, Integer, %OldFormat%
}
else if !encodeuri
out .= "&#" . Asc(A_LoopField) . ";"
else
out .= "%26%23" . Asc(A_LoopField) . "%3B"
return out
}
test =
(Join<br>
ch 化粧品ch ch ch ch 通販
€
)
Msgbox % ConvertText("test")
ConvertText(strHTML)
{
doc := ComObjCreate("HTMLfile")
doc.write(strHTML)
return doc.body.innerText
} ; http://ahk8.com/qa/139#175
jSplode(str,del) {
;////////////////jSplode by TLM 12.31.12
sc:=ComObjCreate("ScriptControl"),sc.Language:="JScript"
js:="str='" str "';aR=str.split(""" del """);", sc.ExecuteStatement(js)
Return sc.Eval("aR")
} ; http://www.autohotkey.com/board/topic/90130-is-there-any-way-to-execute-javascript-code-via-ahk/
; Unicode2Ansi(UUU, rUUU, 0)
Unicode2Ansi(ByRef wString, ByRef sString, CP = 0) ; 这个函数是从论坛上抄下来的
{
nSize := DllCall("WideCharToMultiByte", "Uint", CP, "Uint", 0, "Uint", &wString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte", "Uint", CP, "Uint", 0, "Uint", &wString, "int", -1, "str", sString, "int", nSize, "Uint", 0, "Uint", 0)
}