qmqyqj 发表于 2020-4-10 11:16:22

获取文本内某段内容

本帖最后由 qmqyqj 于 2020-4-10 16:40 编辑

有一段文本内容如下


URL=https://www.yousyun.com/rest/XGT/GX/updates.txt
ID={E53138B6-30FF-4DEB-A104-E47EE1F9C3F2}
Flags=PerMachine|ShowConfigOptionsButton
DownloadsFolder=C:\ProgramData\优云软件\
ApplicationVersion=2.4.9.0
CheckFrequency=2
DefaultCommandLine=/checknow -minuseractions

怎么获取 ApplicationVersion=2.4.9.0 这一段后面的 2.4.9.0 内容(这个内容是随机变化的)并设置为变量


以下这段代码只能根据ApplicationVersion=2.4.9.0 所在的行数进行获取,如果ApplicationVersion=2.4.9.0所在的行数变化了,获取的就是错误的信息,想问下,能不能直接进行搜索 ApplicationVersion 以获得后面 2.4.9.0的值;望指教
;将软件版本信息写入注册表
(defun List_FromFile (fn / f l ll)
(if (setq f (open (findfile fn) "r"))
   (progn
   (while (setq l (read-line f))
       (setq ll (consl ll))
   )
   (close f)
   )
)
(reverse ll)
)
(setq data_file_patch (strcat "C:/update.ini"));;设文件路径
(setq lst (List_FromFile data_file_patch));;get list
(setq ls (nth 6 lst));;获取文件中的第5个数据
(setq banben (substr ls 20))



pxt2001 发表于 2020-4-10 13:16:25

(wcmatch str"ApplicationVersion*l"

qmqyqj 发表于 2020-4-12 20:43:33

本帖最后由 qmqyqj 于 2020-4-12 20:46 编辑

pxt2001 发表于 2020-4-10 13:16
(wcmatch str"ApplicationVersion*l"
(defun List_FromFile (fn / f l ll)
(if (setq f (open (findfile fn) "r"))
   (progn
   (while (setq l (read-line f))
       (setq ll (consl ll))
   )
   (close f)
   )
)
(reverse ll)
)
(setq data_file_patch(strcat "C:/update.ini"));;设文件路径
(setq lst (List_FromFile data_file_patch));;get list
(setq test 1)
(while (<= test 10)
(setq ls (nth test lst));;循环获取数据
(if (= T (wcmatch ls "ApplicationVersion*"))
    (setq banben (substr ls 20));将需要获取的数据设为变量
)
    (setq test (1+ test))
(prin1)
)是不是这样?有没有更好的办法,还有这个有时候会报错,也不知道怎么回事错误提示:_.copyhist命令: ; 错误: 参数类型错误: stringp nil

页: [1]
查看完整版本: 获取文本内某段内容