|
[分享][原创]字符与Charcode互换
来源: 点击数:1790 评论数:0 评论 | 收藏 | 复制
时 间:2007-12-10 7:28:57
作 者:cuxun
摘 要:字符与Charcode互换
正 文:
Public Function CharToCharcode(ByVal CharName As String, Optional ShowType As Integer = 1)
'===============================================================================
'-函数名称: CharToCharcode
'-功能描述: 字符转CHARCODE
'-输入参数说明: 参数1:CharName 字符串
' 参数2:ShowType 显示类型
'-返回参数说明: Charcode值
'-使用语法示例: CharToCharcode("我是真的真的很爱你",3)
'-参考:
'-使用注意:
'-兼容性: 2000,XP,2003
'-作者: 何勇, Email:Cuxun@qq.com ,QQ:100810401
'-更新日期: 2007-9-9
'===============================================================================
Dim intLen As Integer
Dim i As Integer
On Error GoTo Err:
intLen = Len(CharName)
If intLen = 0 Then
MsgBox "没有字符需要转换!", vbCritical
Exit Function
End If
For i = 1 To intLen
Select Case ShowType
Case 1 ''只显示CharCode值
CharToCharcode = CharToCharcode & " " & AscW(Mid(CharName, i, 1))
Case 2 ''分别显示相关的CharCode值
CharToCharcode = CharToCharcode & Mid(CharName, i, 1) & " (" & AscW(Mid(CharName, i, 1)) & ") "
Case 3 ''显示字符转换的内容
CharToCharcode = CharToCharcode & " Chrw(" & AscW(Mid(CharName, i, 1)) & ") "
''最后一个不加&字符
If i < intLen Then CharToCharcode = CharToCharcode & "&"
Case 4 ''分别显示相关的字符及CharCode值
CharToCharcode = CharToCharcode & Mid(CharName, i, 1) & " Chrw(" & AscW(Mid(CharName, i, 1)) & ") "
End Select
Next
Err:
If Err.Number <> 0 Then MsgBox "出错了,错误代码:" & Err.Number & ",错误说明:" & Err.Description, vbInformation
Exit Function
End Function
Public Function CharcodeToChar(ByVal StrCharcode As String, Optional strBreak As String = " ", Optional ShowType As Integer = 1)
'===============================================================================
'-函数名称: CharcodeToChar
'-功能描述: CHARCODE转字符
'-输入参数说明: 参数1:StrCharcode 以空格分隔的数字字符串
' 参数2:strBreak &nbs
|
|