GregGleason 发表于 2022-7-5 15:46:15

字符串比较-不为E

我有一个例行程序,读取两个文件和报告,如果有差异。
 
数据放在文件1的“out1”和文件2的“out2”中。
 
作为测试,我让它读取相同的文件。它说他们不平等。
 
当我这样做时,它会报告“是的!!”
 
当我这样做时,它会报告一个“否”
 
有什么想法吗?
 
以下是完整的例行程序:
 

(defun c:ctf (/ fil fl i mycount out1 out2 rec)
;; String to List-Lee Mac
;; Separates a string using a given delimiter
;; str - String to process
;; del - Delimiter by which to separate the string
;; Returns: List of strings
(defun lm:str->lst (str del / pos)
   (if    (setq pos (vl-string-search del str))
   (cons (substr str 1 pos) (lm:str->lst (substr str (+ pos 1 (strlen del))) del))
   (list str)
   )
)   ; End of lm:str->lst
; ===========================================================================================================
; Read File 1

(setq fl nil)
(setq fil nil)
(if (setq fl (open "C:\\Users\\ggleason\\Documents\\CADWorx\\CADWorx.Projects\\Exxon.Joliet.2015-151\\IsoLayers\\ExxonMobil.Iso.Border.Acad.v.2007.dwg.txt" "r"))
   (progn
      (setq mycount 0)
      (while (setq fil (read-line fl))
         (setq mycount (1+ mycount))
         ; SYNTAX: (princ "\nMy Name is \nJohn")(princ)
         ; (princ mycount)(princ "\n")
         (setq out1 (cons (lm:str->lst fil "\t") out1))
      )   ; End of "While" loop
      (close fl)
      (princ (strcat (itoa mycount) " records read in File 1\n"))
   )
)   ; End of "If" statement for File 1
;; Reverse results to put them in correct order
(setq out1 (reverse out1))
; End of File 1
; ===========================================================================================================
; Read File 2

(setq fl nil)
(setq fil nil)
(if (setq fl (open "C:\\Users\\ggleason\\Documents\\CADWorx\\CADWorx.Projects\\Exxon.Joliet.2015-151\\IsoLayers\\ExxonMobil.Iso.Border.Acad.v.2007.dwg.txt" "r"))
   (progn
      (setq mycount 0)
      (while (setq fil (read-line fl))
         (setq mycount (1+ mycount))
         ; SYNTAX: (princ "\nMy Name is \nJohn")(princ)
         ; (princ mycount)(princ "\n")
         (setq out2 (cons (lm:str->lst fil "\t") out2))
      )   ; End of "While" loop
      (close fl)
      (princ (strcat (itoa mycount) " records read in File 2\n"))
   )
)   ; End of "If" statement for File 2
;; Reverse results to put them in correct order
(setq out2 (reverse out2))
; End of File 2
; ===========================================================================================================
         ; SYNTAX: (if (= 1 3) "YES!!" "no.")
(if (= out1 out2)
    (princ "\nYES!!")
    (princ "\nno.")
)
(princ "\n ------------------------------------------------")
(princ "\n")
(princ out1)
(princ "\n ------------------------------------------------")
(princ "\n")
(princ out2)
(princ "\n ------------------------------------------------")
(princ)
)                  ; End of c:ctf
Greg

BIGAL 发表于 2022-7-5 15:57:15

您为什么不比较从这两个文件中读取的每一行?我在一个测试文件上做了代码,结果没有。

Lee Mac 发表于 2022-7-5 16:02:35

根据文档,应将“=”函数用于数字或字符串比较,而不是列表比较-请注意:
_$ (= '(1 2 3) '(1 2 3))
nil
相反,您应该使用equal函数。
_$ (equal '("a" "b" "c") '("a" "b" "c"))
T

Grrr 发表于 2022-7-5 16:12:07

除了Lee最明显的建议(使用equal函数),如果只处理字符串列表,还有另一种选择:
 
(vl-every '= '("a" "b" "c") '("a" "b" "c") '("a" "b" "c"))
 
因此:
 
(vl-every '= ListOfStrings1 ListOfStrings2 ListOfStrings3 ...)
 
甚至:
 
7
 
尽管我会使用equal,因为它适用于嵌套列表。

GregGleason 发表于 2022-7-5 16:21:53

 
我本想这么做,但我不知道该怎么做。
 
格雷格

GregGleason 发表于 2022-7-5 16:24:42

 
谢谢你澄清这一点。
 
此外,我感谢您提供给我们学习的所有重要信息。
 
格雷格

GregGleason 发表于 2022-7-5 16:33:56

 
这是很好的信息。非常感谢。
 
格雷格

Stefan BMR 发表于 2022-7-5 16:45:04

vl every’=和equal之间有一个很大的差异
8

Grrr 发表于 2022-7-5 16:52:37

 
谢谢你指出这一点,斯特凡!
我忘了vl每个进程都像mapcar。
因此,该建议应与列表的等长检查结合使用。
页: [1]
查看完整版本: 字符串比较-不为E