VB 使用C语言Escape的方法
2010-05-13 22:15
246 查看
在C语言中,escape的符号很好用,
比如
"中国一定强"
这个字串可以写成:
"/x4E2D/x56FD/x4E00/x5B9A/x5F3A"
用字元编码编写程序,在其他不同语言的windows运作时,比较不会有问题。
(我尽量不想在程序中写入中文)
但是vb如果全部要用字元编码写的话,就会很麻烦而且一个一个都要手写成:
ChrW(&H4E2D) & ChrW(&H56FD) & ChrW(&H4E00) & ChrW(&H5B9A) & ChrW(&H5F3A)
所以我写了一条短短的function:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function EscToStr(ByVal c As String) As String
Dim tmp, str1, str2, str3, str4 As String
Dim i, outend1, outend2 As Integer
i = 1
outend1 = 1
Do While outend1 <> 0
str1 = c
outend1 = InStr(i, str1, "/x")
i = outend1 + 1
outend2 = InStr(i, str1, "/x")
If outend2 = 0 Then
outend2 = Len(str1) + 1
End If
str2 = Mid(str1, outend1 + 2, outend2 - outend1 - 2)
str3 = "&H" & str2
str4 = ChrW(str3)
tmp = tmp & str4
If outend2 = (Len(str1) + 1) Then
outend1 = 0
End If
Loop
EscToStr = tmp
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
应用时比如:
Form1.Text=EscToStr("/x4E2D/x56FD/x4E00/x5B9A/x5F3A")
显示出的表单文字就成为
"中国一定强"
比如
"中国一定强"
这个字串可以写成:
"/x4E2D/x56FD/x4E00/x5B9A/x5F3A"
用字元编码编写程序,在其他不同语言的windows运作时,比较不会有问题。
(我尽量不想在程序中写入中文)
但是vb如果全部要用字元编码写的话,就会很麻烦而且一个一个都要手写成:
ChrW(&H4E2D) & ChrW(&H56FD) & ChrW(&H4E00) & ChrW(&H5B9A) & ChrW(&H5F3A)
所以我写了一条短短的function:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function EscToStr(ByVal c As String) As String
Dim tmp, str1, str2, str3, str4 As String
Dim i, outend1, outend2 As Integer
i = 1
outend1 = 1
Do While outend1 <> 0
str1 = c
outend1 = InStr(i, str1, "/x")
i = outend1 + 1
outend2 = InStr(i, str1, "/x")
If outend2 = 0 Then
outend2 = Len(str1) + 1
End If
str2 = Mid(str1, outend1 + 2, outend2 - outend1 - 2)
str3 = "&H" & str2
str4 = ChrW(str3)
tmp = tmp & str4
If outend2 = (Len(str1) + 1) Then
outend1 = 0
End If
Loop
EscToStr = tmp
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
应用时比如:
Form1.Text=EscToStr("/x4E2D/x56FD/x4E00/x5B9A/x5F3A")
显示出的表单文字就成为
"中国一定强"
相关文章推荐
- 使用Ajax时常用的转码方法encodeURI,escape,encodeURI
- C语言中的enum(枚举)使用方法
- VB使用shell函数打开外部exe程序的实现方法
- c语言中的qsort方法的使用
- C语言memset函数使用方法详解
- c语言中static使用方法(转)
- [VB.NET]vb.net中使用treenodecollection的add 方法出错
- 【转帖】C语言的常用库函数使用方法分析及用途
- C语言中关于%d的使用方法
- C语言静态函数库的制作和使用方法
- VB.NET从VS2003升到VS2005后报表无法使用的解决方法
- C语言vector的使用方法 C++中vector的用法详解
- c语言操作文本的基本使用方法
- C语言inline函数的使用方法
- c语言 json使用方法
- 【Vegas原创】TreeView操作数据库的使用方法(VB)
- C语言使用cmd命令并获取输出方法
- vb.net 使用windows API方法
- C语言中const关键字使用方法及使用场景