乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 14|回复: 8

[编程交流] 字符串比较-不为E

[复制链接]

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 15:46:15 | 显示全部楼层 |阅读模式
我有一个例行程序,读取两个文件和报告,如果有差异。
 
数据放在文件1的“out1”和文件2的“out2”中。
 
作为测试,我让它读取相同的文件。它说他们不平等。
 
当我这样做时,它会报告“是的!!”
 
当我这样做时,它会报告一个“否”
 
有什么想法吗?
 
以下是完整的例行程序:
 
  1. (defun c:ctf (/ fil fl i mycount out1 out2 rec)
  2. ;; String to List  -  Lee Mac
  3. ;; Separates a string using a given delimiter
  4. ;; str - [str] String to process
  5. ;; del - [str] Delimiter by which to separate the string
  6. ;; Returns: [lst] List of strings
  7. (defun lm:str->lst (str del / pos)
  8.    (if    (setq pos (vl-string-search del str))
  9.      (cons (substr str 1 pos) (lm:str->lst (substr str (+ pos 1 (strlen del))) del))
  10.      (list str)
  11.    )
  12. )   ; End of lm:str->lst
  13. ; ===========================================================================================================
  14. ; Read File 1
  15. (setq fl nil)
  16. (setq fil nil)
  17. (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"))
  18.    (progn
  19.       (setq mycount 0)
  20.       (while (setq fil (read-line fl))
  21.          (setq mycount (1+ mycount))
  22.          ; SYNTAX: (princ "\nMy Name is \nJohn")(princ)
  23.          ; (princ mycount)(princ "\n")
  24.          (setq out1 (cons (lm:str->lst fil "\t") out1))
  25.       )   ; End of "While" loop
  26.       (close fl)
  27.       (princ (strcat (itoa mycount) " records read in File 1\n"))
  28.    )
  29. )   ; End of "If" statement for File 1
  30. ;; Reverse results to put them in correct order
  31. (setq out1 (reverse out1))
  32. ; End of File 1
  33. ; ===========================================================================================================
  34. ; Read File 2
  35. (setq fl nil)
  36. (setq fil nil)
  37. (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"))
  38.    (progn
  39.       (setq mycount 0)
  40.       (while (setq fil (read-line fl))
  41.          (setq mycount (1+ mycount))
  42.          ; SYNTAX: (princ "\nMy Name is \nJohn")(princ)
  43.          ; (princ mycount)(princ "\n")
  44.          (setq out2 (cons (lm:str->lst fil "\t") out2))
  45.       )   ; End of "While" loop
  46.       (close fl)
  47.       (princ (strcat (itoa mycount) " records read in File 2\n"))
  48.    )
  49. )   ; End of "If" statement for File 2
  50. ;; Reverse results to put them in correct order
  51. (setq out2 (reverse out2))
  52. ; End of File 2
  53. ; ===========================================================================================================
  54.          ; SYNTAX: (if (= 1 3) "YES!!" "no.")
  55. (if (= out1 out2)
  56.     (princ "\nYES!!")
  57.     (princ "\nno.")
  58. )
  59. (princ "\n ------------------------------------------------")
  60. (princ "\n")
  61. (princ out1)
  62. (princ "\n ------------------------------------------------")
  63. (princ "\n")
  64. (princ out2)
  65. (princ "\n ------------------------------------------------")
  66. (princ)
  67. )                    ; End of c:ctf
Greg
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 15:57:15 | 显示全部楼层
您为什么不比较从这两个文件中读取的每一行?我在一个测试文件上做了代码,结果没有。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:02:35 | 显示全部楼层
根据文档,应将“=”函数用于数字或字符串比较,而不是列表比较-请注意:
  1. _$ (= '(1 2 3) '(1 2 3))
  2. nil

相反,您应该使用equal函数。
  1. _$ (equal '("a" "b" "c") '("a" "b" "c"))
  2. T
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 16:12:07 | 显示全部楼层
除了Lee最明显的建议(使用equal函数),如果只处理字符串列表,还有另一种选择:
 
  1. (vl-every '= '("a" "b" "c") '("a" "b" "c") '("a" "b" "c"))

 
因此:
 
  1. (vl-every '= ListOfStrings1 ListOfStrings2 ListOfStrings3 ...)

 
甚至:
 
  1. 7

 
尽管我会使用equal,因为它适用于嵌套列表。
回复

使用道具 举报

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 16:21:53 | 显示全部楼层
 
我本想这么做,但我不知道该怎么做。
 
格雷格
回复

使用道具 举报

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 16:24:42 | 显示全部楼层
 
谢谢你澄清这一点。
 
此外,我感谢您提供给我们学习的所有重要信息。
 
格雷格
回复

使用道具 举报

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 16:33:56 | 显示全部楼层
 
这是很好的信息。非常感谢。
 
格雷格
回复

使用道具 举报

0

主题

375

帖子

385

银币

限制会员

铜币
-7
发表于 2022-7-5 16:45:04 | 显示全部楼层
vl every’=和equal之间有一个很大的差异
  1. 8
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 16:52:37 | 显示全部楼层
 
谢谢你指出这一点,斯特凡!
我忘了vl每个进程都像mapcar。
因此,该建议应与列表的等长检查结合使用。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 23:57 , Processed in 0.560697 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表