|
|
发表于 2021-12-28 15:34:09
|
显示全部楼层
回帖奖励 +2 鱼币
本帖最后由 hrpzcf 于 2021-12-28 15:38 编辑
- def cvtudc(udcstr: str) -> str:
- udc, start = "\\udc", 0
- udcstr = repr(udcstr).strip("'")
- max_i = len(udcstr) - 1
- while True:
- u1 = udcstr.find(udc, start)
- if u1 == -1 or u1 + 1 > max_i or u1 + 4 > max_i:
- break
- start = u1 + 1
- u2 = udcstr.find(udc, start)
- if u2 == -1 or u2 + 4 > max_i or u2 + 6 > max_i:
- break
- b1 = udcstr[u1 + 4 : u2]
- b2 = udcstr[u2 + 4 : u2 + 6]
- new = bytes([int(b1, 16), int(b2, 16)]).decode("gbk")
- udcstr = udcstr.replace(udcstr[u1 : u2 + 6], new, 1)
- return udcstr
- # 使用cvtudc函数来把str2转换成可读字符串,理论上像str2的字符串,都可以用cvtudc来转
- str2 = "1263\udcb5\udcc4\udcd4\udcda\udcd6\udcc6\udcc6\udcb7\udcd0\udcc5\udccf\udca2\udcbb\udce3\udcd7\udcdc.xlsx"
- print(cvtudc(str2)) # 结果:1263的在制品信息汇总.xlsx
复制代码 |
|