Author Topic: Compare 2 strings & return a list of strings with the differences?  (Read 8308 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #30 on: December 22, 2006, 03:25:47 PM »
So am I out of luck now?
I thought we where making some good progress before this posting one different (unrelated) sites issue came up...
Think the issue now is the Holidays, not the cross posting issue.  You may have to wait until next year, unless there are some people like me who have to work for the next couple of weeks, and have time/desire to do what you are asking.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #31 on: December 22, 2006, 03:57:42 PM »
Here.  This is as close as I can get what I think would be useful.
Code: [Select]
(defun CompareStrings (String1 String2 / cnt1 cnt2 Str tempStr StrList)

(setq cnt1 1)
(setq cnt2 1)
(setq Str "")
(while (and (<= cnt1 (strlen String1)) (<= cnt2 (strlen String2)))
 (setq tempStr (substr String2 cnt2 1))
 (if (= (substr String1 cnt1 1) tempStr)
  (setq Str (strcat Str tempStr))
  (progn
   (if (/= Str "")
    (setq StrList (cons Str StrList))
   )
   (setq Str tempStr)
   (setq cnt2 (1+ cnt2))
   (while (and (/= (substr String1 cnt1 1) (setq tempStr (substr String2 cnt2 1))) (<= cnt2 (strlen String2)))
    (setq Str (strcat Str tempStr))
    (setq cnt2 (1+ cnt2))
   )
   (setq StrList (cons (list Str) StrList))
   (setq Str "")
  )
 )
 (setq cnt1 (1+ cnt1))
 (setq cnt2 (1+ cnt2))
)
(if (and (/= Str "") (/= Str (car StrList)))
 (setq StrList (cons Str StrList))
)
(if (<= cnt1 (strlen String1))
 (reverse (cons (substr String1 cnt1) StrList))
 (reverse StrList)
)
)
Returned this for your two test strings in the first post.
Quote
Command: (comparestrings a b)

("This is" ("n't") "a test")

Command: (comparestrings a b)

("1" ("x3") "3")
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #32 on: December 22, 2006, 04:31:24 PM »
So am I out of luck now?

What have you coded thus far? Maybe we can get back into it, it is an interesting problem.

I've got an idea! How about looking at the source code for GNU diff. Yea it's in C but you might be able to glean some info on how they do it and translate that into autolisp.
TheSwamp.org  (serving the CAD community since 2003)


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #34 on: December 26, 2006, 04:24:13 AM »
good find Daniel ...

that boy < Joshua Tauberer > sure has a heavy reading list  :?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.