明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 833|回复: 5

[基础教程] 求助,读txt乱码

[复制链接]
发表于 2020-6-17 08:27 | 显示全部楼层 |阅读模式
princ tm 是乱码状态,即使txt里面写的是英文字母也乱码,TKS
(defun C:xwy( / tt f txt tm cl xx xk)
(setq f (open "C:\\jx.txt" "r"))
(read-line f )
(while (setq txt (read-line f))
       (setq tm (substr txt 1 20))
       (setq cl (substr txt 21 3))
       (setq xx (substr txt 29 10))
       (setq xk (substr txt 44 4))
  )
;;(command "_layer" "n" tm "c" cl tm "l" xx tm "lw" xk tm "") )
   (PRINC "图层加载OK")
  (princ tm)
  (princ "It's OK")
  )

 楼主| 发表于 2020-6-17 11:00 | 显示全部楼层
重新测试了,英文不乱码,中文乱码
发表于 2020-6-18 08:34 来自手机 | 显示全部楼层
通常是由于文件编码不是 ascii 是 utf-8或其它类似的吧。记事本打开文件,“另存为” 编码选择 ascii,重新保存再试试。
 楼主| 发表于 2020-6-18 15:42 | 显示全部楼层
dunkel 发表于 2020-6-18 08:34
通常是由于文件编码不是 ascii 是 utf-8或其它类似的吧。记事本打开文件,“另存为” 编码选择 ascii,重新 ...

是编码问题,需要用GB2312
谢谢答复
发表于 2020-10-8 11:00 | 显示全部楼层
slysmart 发表于 2020-6-18 15:42
是编码问题,需要用GB2312
谢谢答复

新的 2021 版默认使用 utf8了,且open函数增加了编码的参数。

另外,通过txt等外部文件记录与读取数据,不要用这种笨办法,应该参考更加可靠的关键字key与值value的方式,例如ini,cfg这样的格式。
发表于 2023-4-3 15:18 | 显示全部楼层
e2002 发表于 2020-10-8 11:00
新的 2021 版默认使用 utf8了,且open函数增加了编码的参数。

另外,通过txt等外部文件记录与读取数据 ...

open函数增加了编码的参数,增加的参数是是什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-17 14:08 , Processed in 0.176797 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表