以下四个函数对你应该有用:- ;;文本操作函数
- ;;作者:明经通道 mccad
- ;;将文本文件中的内容转换为列表
- (defun Get_Txt(datfile / tmplst x fn)
- (setq fn (open datfile "r"))
- (while (setq x (read-line fn))
- (setq tmplst(append tmplst(list x)))
- )
- (close fn)
- tmplst
- )
- ;;获取文本文件的行数
- (defun Get_Lines(datfile / tmplst x fn)
- (setq fn(open datfile "r"))
- (while (read-line fn)
- (setq tmplst (+ 1 tmplst))
- )
- (close fn)
- tmplst
- )
- ;;获取文本文件中指定行数的文本内容
- (defun Get_Num_Txt (datfile num / fn txt)
- (setq fn(open datfile "r"))
- (repeat (+ 1 num)
- (setq txt(read-line fn))
- )
- (close fn)
- txt
- )
- ;;获取文本文件中指定文本内容的行数(位置)
- (defun Get_Txt_Num (datfile txt / num havetxt fn txtline)
- (setq havetxt T)
- (setq num 0)
- (setq fn (open datfile "r"))
- (while havetxt
- (setq txtline (read-line fn))
- (if txtline
- (if(= txt txtline)
- (setq havetxt nil)
- (setq num(+ 1 num))
- )
- (setq havetxt nil)
- )
- )
- (close fn)
- (if (not txtline)
- (setq num nil)
- )
- num
- )
|