高令 发表于 2024-5-15 19:34:18

read函数求助


原始数据

tr1.15,tr1.9,tr.3.1,ld1.76
tr1.35,tr1.1,tr.3.4,ld1.56
tr1.12,tr1.2,tr.3.44,ld1.36
tr1.14,tr1.3,tr.3.32,ld1.56
tr1.25,tr1.5,tr.3.33,ld1.566


(defun C:SDS()
         (setq sjwj (open (getfiled "请选取数据文件" "" "txt;dat" 0) "r"))
         (setq wjlb nil)
(while (setq mhxx(read-line sjwj))
(while (vl-string-search "," mhxx)
         (setq mhxx(vl-string-subst " " "," mhxx)))
       
         (setq mhlb (read (strcat "(" mhxx ")")))
         (setq wjlb(append wjlb(list mhlb))))
)

转换为列表后 read把每个元素小数点后面去掉了,并全部改为了大写,,求助该怎么写

guosheyang 发表于 2024-5-15 19:57:12

你 参考下高飞鸟的代码
(defun mysplit (str delim / lst i len);高飞鸟代码
(setq len (strlen delim))
(while (setq i (vl-string-search delim str))
    (setq lst (cons (substr str 1 i) lst))
    (setq str (substr str (+ 1 len i)))
)
(setq lst (cons str lst))
(reverse lst)
)

guosheyang 发表于 2024-5-15 20:14:36

(defun C:SDS(/ MHLB MHXX SJWJ WJLB)
         (setq sjwj (open (getfiled "请选取数据文件" "" "txt;dat" 0) "r"))
(while (setq mhxx(read-line sjwj))
         (setq mhlb (cons(mysplit mhxx ",")mhlb))

)
(reverse mhlb)
)

bonny 发表于 2024-5-15 20:16:40

本帖最后由 bonny 于 2024-5-15 21:16 编辑

仅供参考仅供参考仅供参考

菜卷鱼 发表于 2024-5-16 17:04:15

把中间那段换成下面的试一试
(while (vl-string-search "," mhxx)
         (setq mhxx(vl-string-subst "\" \"" "," mhxx)))
         (setq mhlb (read (strcat "(\"" mhxx "\")")))
)
页: [1]
查看完整版本: read函数求助