网页上的Unicode字符串转汉字

qq_39322367 2017-12-14 11:05:38
VB6
有字符串CCED:欢迎回家17/1211
其中字母数字跟符号不要转换,只想吧字符串中欢迎回家转换成汉字即可,
chw(27426)倒是可以转出来,可是我的字符串是批量随机的,如果发现&#的就转成汉字,该如何做呢,求帮助,谢谢
$("#a_source").val('');
for (var i=0; i<code.length; i++)
$("#a_source").val($("#a_source").val() + String.fromCharCode(code[i].replace(/[&#;]/g, '')));
}
这是网页在线转换的代码,用vb6该如何做呢?
...全文
441 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_39322367 2017-12-14
  • 打赏
  • 举报
回复
引用 4 楼 Chen8013 的回复:
参考一下这个:
Private Sub Command1_Click()
   Dim strCode As String
   Dim strText As String
   Dim i&, j&, k As Long

   strCode = "有字符串CCED:欢迎回家17/1211"
   i = InStr(1&, strCode, "&#")
   If (0& = i) Then
      strText = strCode
   Else
      strText = Left$(strCode, i - 1&)
      Do
         If (0& = i) Then
            k = Len(strCode)
            strText = strText & Mid$(strCode, 1& + j, k - j)
            Exit Do
         End If
         j = InStr(i, strCode, ";")
         strText = strText & ChrW$(Mid$(strCode, 2& + i, j - i - 2&))
         i = InStr(j, strCode, "&#")
         k = i - j
         If (1& < k) Then strText = strText & Mid$(strCode, 1& + j, k - 1&)
      Loop
   End If
   Call MsgBox(strText, 64, "转换结果")
End Sub
输出结果: 有字符串CCED:欢迎回家17/1211
太感谢拉,谢谢您,也谢谢of123,结贴,学习拉,感谢
舉杯邀明月 2017-12-14
  • 打赏
  • 举报
回复
参考一下这个:
Private Sub Command1_Click()
   Dim strCode As String
   Dim strText As String
   Dim i&, j&, k As Long

   strCode = "有字符串CCED:欢迎回家17/1211"
   i = InStr(1&, strCode, "&#")
   If (0& = i) Then
      strText = strCode
   Else
      strText = Left$(strCode, i - 1&)
      Do
         If (0& = i) Then
            k = Len(strCode)
            strText = strText & Mid$(strCode, 1& + j, k - j)
            Exit Do
         End If
         j = InStr(i, strCode, ";")
         strText = strText & ChrW$(Mid$(strCode, 2& + i, j - i - 2&))
         i = InStr(j, strCode, "&#")
         k = i - j
         If (1& < k) Then strText = strText & Mid$(strCode, 1& + j, k - 1&)
      Loop
   End If
   Call MsgBox(strText, 64, "转换结果")
End Sub
输出结果: 有字符串CCED:欢迎回家17/1211
舉杯邀明月 2017-12-14
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
   Dim strCode As String
   Dim strText As String
   Dim i&, j As Long

   strCode = "有字符串CCED:欢迎回家17/1211"
   strText = ""   ' 从“理论上说”这句是多余的
   j = 1&
   Do
      i = InStr(j, strCode, "&#")
      If (0& = i) Then Exit Do
      j = InStr(i, strCode, ";")
      If (0& = j) Then
         strText = strText & ChrW$(Mid$(strCode, 2& + i))
      Else
         strText = strText & ChrW$(Mid$(strCode, 2& + i, j - i - 2&))
      End If
   Loop
   Call MsgBox(strText, 64, "转换结果")
End Sub
那段编码的结果是: 欢迎回家
qq_39322367 2017-12-14
  • 打赏
  • 举报
回复
引用 1 楼 of123 的回复:
采用正则表达式比较合适。
额。。。。我就是不会用vb写,您看看,如果用vb写的话,改怎么写呢,麻烦您了,谢谢
of123 2017-12-14
  • 打赏
  • 举报
回复
采用正则表达式比较合适。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧