|
本帖最后由 itianda 于 2011-12-24 00:16 编辑
今早写的,标准C++实现,为了推动C++标准化进程用了auto关键字,想用VC6编译的请自行修改变量定义。
不多说,看下效果:
格式化前(网上找的代码,故意丑化了下^_^):
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn, i, 1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn, i + 1, 1))
strReturn = strReturn & Chr( _
CLng(ThisCharCode) * _
&H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
格式化后:
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn, i, 1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn, i + 1, 1))
strReturn = strReturn & Chr( _
CLng(ThisCharCode) * _
&H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
效果还凑和,代码不多,200多行,一些细节没有很好处理到,比如用冒号连结多行语句的情况。
进一步可以弄成IDE插件之类的东西,不过暂时可能没时间弄了。
看代码请去我的博客:http://www.programup.com/blog/archives/32
下载EXE程序:http://www.programup.com/files/puvbformatter.zip或者3楼附件 |
|