Christina_ 发表于 2022-7-5 16:26:52

读取ini文件,但不读取命令

您好,CadTutor用户,
 
我通过lisp ini文件读取(ini\u read“Myfile.ini”“OPTIONS”“Name1”)。
 
我的文件。ini:
 

Name1=10
Name2=210       
Name3=0
 
这将很好地返回我“10”。
 
问题是,我想对ini文件进行注释,但不需要在结果中进行注释:
[选项]
名称1=10“注释1”
名称2=210“注释2”
名称3=0“注释3”
 
有人可以编辑我的代码吗?
如果注释以/comment或#comment或…
 
Lisp代码:
(defun ini_read (inifile section entry )
(if (and (= 'STR (type section)) (/= "[" (substr section 1 1))) (setq section (strcat "[" section "]")))
(setq section (ini_readsection inifile section))
(cadr (assoc entry section))
)
 
(defun ini_readsection (inifile section / ofile line result )
(if (and (= 'STR (type section)) (/= "[" (substr section 1 1))) (setq section (strcat "[" section "]")))
(if (findfile inifile)
        (cdr (assoc section (ini_readini (findfile inifile))))
        (alert (STRCAT inifile "\nNiet Gevonden!"))
)
)
 
谢谢你阅读我的问题
克里斯蒂娜

rlx 发表于 2022-7-5 16:45:38

海克里斯蒂娜,
 
 
zoiets?
 
 

; strip comment
; (strip-comment "hallo ; goodbey" ";")
(defun strip-comment ( $s $c / i )(if (setq i (vl-string-position (ascii $c) $s 1))(substr $s 1 i) $s))

 
 
gr.Rlx

Christina_ 发表于 2022-7-5 16:47:27

Dag Rlx,
 
 
非常感谢您的回复,但很抱歉,我不知道如何在我的代码中使用您的代码
 
 
希望你不介意我把代码放在附件里
测验拉链

rlx 发表于 2022-7-5 17:02:19

 
我看到您在ini值之后使用了空格(spatie)和制表符,所以我在制表符(“\t”)处打断ini值(字符串),然后删除空格。
 
如果ini值从不包含空格,也可以在空格字符处打断ini值
 
(strip-comment (cadr (assoc entry section)) " ")
 


;(ini_read "Test.ini" "OPTIONS" "Name1")
;(ini_read (findfile "Test.ini") "OPTIONS" "Name1")

(vl-load-com)
(defun ini_read (inifile section entry / result)
   (if (and (= 'STR (type section)) (/= "[" (substr section 1 1))) (setq section (strcat "[" section "]")))
   (setq section (ini_readsection inifile section))
   ; remove everything from the first tab ("\t")
   (setq result (strip-comment (cadr (assoc entry section)) "\t"))
   ; result is "10 " (with a space (spatie) , so remove space "10 " -> "10"
   (vl-string-right-trim " " result)
; you can combine line 2,3 & 4 into one line :
; (vl-string-right-trim " " (strip-comment (cadr (assoc entry (ini_readsection inifile section))) "\t"))
)

;(vl-string-right-trim character-set string)

; strip comment
; (strip-comment "hallo ; goodbye" ";")
(defun strip-comment ( $s $c / i )(if (setq i (vl-string-position (ascii $c) $s 1))(substr $s 1 i) $s))

 
gr.Rlx

BIGAL 发表于 2022-7-5 17:10:38

看看这篇文章的李mac代码,你可以使用逗号作为分隔符,并使列表非常容易。
 
http://www.cadtutor.net/forum/showthread.php?100466-Lisp用于从多行文字中删除一行

Christina_ 发表于 2022-7-5 17:18:36

Dag Rlx,
 
这件作品很有魅力,非常感谢你的解释。
最后,我有了我想要的ini文件(mijn dag kan niet meer stuk)。
格罗杰斯,
克里斯蒂娜
@比加尔,
非常感谢您的链接,我们会查看它

rlx 发表于 2022-7-5 17:28:17

 
 
欢迎你,Christina_,succes met je appie:-)
 
 
gr.Rlx
页: [1]
查看完整版本: 读取ini文件,但不读取命令