中英文在线翻译 -开云体育官网入口

 中英文在线翻译 -开云体育官网入口

中英文在线翻译

时间:2022-11-10 23:59
正文资讯

群里聊天,聊到中英文翻译,之前插件里面也写过中英文互译,打开一看不能使用了?what??

群里老哥也是,他之前的翻译代码也无法使用,于是顺手看看,下面是之前的代码:

function fy(str)
    dim xml
    dim url$, engsentence$
    set xml = createobject(&34;msxml2.xmlhttp&34;)
    engsentence = utf8encodeuri(str)
    url1 = &34;http://translate.google.cn/m?hl=en&sl=en&tl=zh-cn&ie=utf-8&prev=_m&q=&34; & engsentence
    url2 = &34;http://translate.google.cn/m?hl=en&sl=zh-cn&tl=en&ie=utf-8&prev=_m&q=&34; & engsentence
    if asc(left(str, 1)) > 0 and asc(left(str, 1)) < 128 then url = url1 else url = url2
    with xml
      .open &34;get&34;, url, false
      .send
       if instr(.responsetext, &34;
&34;) > 0 then fy = split(split(.responsetext, &34;
&34;)(1), &34;
<&34;)(0) else msgbox &34;error&34;: exit function end if end with end function function utf8encodeuri(szinput) dim wch, uch, szret dim x dim nasc, nasc2, nasc3 if szinput = &34;&34; then utf8encodeuri = szinput exit function end if for x = 1 to len(szinput) wch = mid(szinput, x, 1) nasc = ascw(wch) if nasc < 0 then nasc = nasc 65536 if (nasc and &hff80) = 0 then szret = szret & wch else if (nasc and &hf000) = 0 then uch = &34;%&34; & hex(((nasc \ 2 ^ 6)) or &hc0) & hex(nasc and &h3f or &h80) szret = szret & uch else uch = &34;%&34; & hex((nasc \ 2 ^ 12) or &he0) & &34;%&34; & _ hex((nasc \ 2 ^ 6) and &h3f or &h80) & &34;%&34; & _ hex(nasc and &h3f or &h80) szret = szret & uch end if end if next utf8encodeuri = szret end function

经过排查,不是请求错误,是返回的结果后对字符串处理出问题了,比如翻译 hello 返回结果其中一部分如下,要获取 你好 这2个汉字,之前的字符串处理方式不对,导致没结果。

修改处理字符串代码为下面的即可

最终结果:

  • 联系开云体育官网入口网页
  • 公众号:起航号
  • 微信:xincanshu