看到有个朋友问了个中文不能完整转换成ANSI二进制码的问题,自己试了下情况,然后做了这个代码,希望对大家有所帮助
Func String2Binary($sString)
Dim $BinaryString
For $i = 1 To StringLen($sString)
$M = StringMid($sString, $i, 1)
For $K = 32 To 126
If $M = Chr($K) Then
$BinaryString &= BinaryMid(Binary($M), 1)
ContinueLoop 2
EndIf
Next
$BinaryString &= BinaryMid(Binary($M & $M), 1)
Next
$BinaryString = StringReplace($BinaryString, '0x', '')
$BinaryString = Binary('0x' & $BinaryString)
Return $BinaryString
EndFunc ;==>String2Binary
再修改把循环检测去掉,提高运行速度:
Func String2Binary($sString)
Dim $BinaryString
For $i = 1 To StringLen($sString)
$STR = StringMid($sString, $i, 1)
If String(Binary($STR)) > 0xFF Then Return Binary($sString)
If String(Binary($STR)) < 0x80 Then
$BinaryString &= String(Binary($STR))
Else
$BinaryString &= String(Binary($STR & $STR))
EndIf
Next
$BinaryString = StringReplace($BinaryString, '0x', '')
Return Binary('0x' & $BinaryString)
EndFunc ;==>String2Binary
[ 本帖最后由 liongodmien 于 2008-11-9 12:01 编辑 ] |