def str2byte(s):
base='0123456789ABCDEF'
i=0
s = s.upper()
s1=''
while i <len(s):
c1=s[i]
c2=s[i+1]
i+=2
b1=base.find(c1)
b2=base.find(c2)
if b1 == -1 or b2 == -1:
return None
s1+=chr((b1 <<4)+b2)
return s1
s = 'C7 EB CE F0 BE C6 BA F3 BC DD B3 B5'.replace(' ','') #去掉空格
s1 = str2byte(s)
print s1.decode('gbk') #以gbk编码解码输出
#结果
>>>s1
'\xc7\xeb\xce\xf0\xbe\xc6\xba\xf3\xbc\xdd\xb3\xb5'
>>>print s1.decode('gbk')
请勿酒后驾车
Dox = InputBox("请输入一个字符")
Loop Until Len(x) = 1
Select Case Asc(LCase(x))
Case 97 To 122
MsgBox "字母字符"
Case 48 To 57
MsgBox "数字字符"
Case Else
MsgBox "其他字符"
End Select
#!/usr/bin/python# -*- coding:utf8 -*-
import binascii
import sys
import os
FILE_PATH = '/Users/wj6/TH'+‘001’
#把文件不同的部分做一个字典,方便检测多个文件,减少重复代码。
m = {
'a':{'file_name':'_a.txt'}
'b':{'file_name':'_b.txt'}
}
#遍历文件
for file_info in m:
fd = open(FILE_PATH + pid[file_info][file_name])
file_b = fd.read()
fd.close()
#做一个标记默认为0
#binascii.b2a_hex()函数换成ascii形式
#程序首先运行else段,遇到回车标记改为1,运行if语句,进行判断是否回车换行在一起。
flag=0
for s in file_b:
asc = binascii.b2a_hex(s)
if flag==1:
if asc=='0a'
flag=0
else:
print "error,only 0d",pid[file_info][file_name]
break
else:
if asc == '0a':
print "error,only 0a",pid[file_info][file_name]
break
if asc=='20':
print "error,only 20",pid[file_info]['file_name']
break
if asc=='22':
print "error,only 22",pid[file_info]['file_name']
break
if asc=='0d':
flag=1