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

0 Members and 1 Guest are viewing this topic.

BazzaCAD

  • Guest
Does anyone have some code that will compare 2 strings & return a list of strings with the differences?
For example:
(setq a "This is a test")
(setq b "This isn't a test")
(StrCompare a b)
("This is" "n't" " a test")

OR

(setq a "123")
(setq b "1x3)
(StrCompare a b)
("1" "x" "3")

Or something similar to this?

uncoolperson

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #1 on: December 15, 2006, 12:57:27 PM »
hmm... i may have to take a break from actual work, this looks to be fun

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #2 on: December 15, 2006, 01:06:18 PM »
vl-string->list
mapcar
eq
cons
chr

...sorry, just thinking out loud.  Yeah, i think i'll participate as well after lunch.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #3 on: December 15, 2006, 01:24:59 PM »
This would be a tough one
Code: [Select]
(setq a "This is a X test")
(setq b "This isn't a test")
(StrCompare a b)
("This is" " n't" " a " "X"  " test")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

BazzaCAD

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #4 on: December 15, 2006, 01:38:04 PM »
Thx for the help guys.
I was thinking of breaking the string up into a list of words separated by the blank space " ". Then compare each word, if they don't match then compare each letter to see what is different.
Or something like that...

(dos_strtokens "This is a test" " ")

uncoolperson

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #5 on: December 15, 2006, 04:41:27 PM »

it's not pretty, it's not perfect... but it's where i'm at so far


Code: [Select]
_$ (setq a "This is a X test")
(setq b "This isnt a test")
"This is a X test"
"This isnt a test"
_$ (compfun a b)
((T "test") (T "This is") (nil "nt") (T " a ") (nil "X "))


the nil and T are to point out if it represents something that is in both or just one.



Code: [Select]
(DEFUN compfun (string1 string2 / next retlist startmis tempstr swap backwards)
  (WHILE (AND (> (STRLEN string1) 0)
      (> (STRLEN string2) 0)
)
    (SETQ startmis (VL-STRING-MISMATCH string1 string2))
    (IF (> startmis 0)
      (SETQ retlist (APPEND (LIST
      (LIST T
    (IF backwards
      (VL-LIST->STRING
(REVERSE
  (VL-STRING->LIST (SUBSTR string1 1 startmis))
)
      )
      (SUBSTR string1 1 startmis)
    )
      )
    )
    retlist
    )
    string1 (SUBSTR string1 (+ 1 startmis))
    string2 (SUBSTR string2 (+ 1 startmis))
      )
    )
    (SETQ next (VL-STRING-SEARCH (SUBSTR string1 1 1) string2))
    (IF (> next 0)
      (SETQ retlist (APPEND (LIST
      (LIST f
    (IF backwards
      (VL-LIST->STRING
(REVERSE (VL-STRING->LIST (SUBSTR string2 1 next))
)
      )
      (SUBSTR string2 1 next)
    )
      )
    )
    retlist
    )
    string2 (SUBSTR string2 (+ next 1))
      )
      (IF swap
(SETQ tempstr string1
      string1 string2
      string2 tempstr
      swap    nil
)
(SETQ string1 (VL-LIST->STRING
  (REVERSE (VL-STRING->LIST string1))
)
      string2 (VL-LIST->STRING
  (REVERSE (VL-STRING->LIST string2))
)
      retlist (REVERSE retlist)
      backwards (= backwards nil)
      swap T
)
      )
    )
  )
  (VL-REMOVE '(nil "")
     (VL-REMOVE '(nil nil)
(APPEND (IF backwared
  (REVERSE retlist)
  retlist
)
(LIST (LIST nil
    (IF backwards
      (VL-LIST->STRING
(REVERSE (VL-STRING->LIST string1))
      )
      string1
    )
      )
      (LIST nil
    (IF backwards
      (VL-LIST->STRING
(REVERSE (VL-STRING->LIST string2))
      )
      string2
    )
      )
)
)
     )
  )
)

BazzaCAD

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #6 on: December 15, 2006, 05:45:08 PM »
WOW, I'm truly impressed, nice work...

This one works great.....
Code: [Select]
(setq a "this is a test")
"this is a test"
(setq b "this isn't a test")
"this isn't a test"
(compfun a b)
((T "this is") (nil "n't") (T " a test"))


But this one returns them out of order, can this be fixed?
Code: [Select]
(setq a "this is a X test")
"this is a X test"
(compfun a b)
((T "test") (T "this is") (nil "n't") (T " a ") (nil "X "))
« Last Edit: December 15, 2006, 05:46:24 PM by BazzaCAD »

BazzaCAD

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #7 on: December 15, 2006, 06:03:29 PM »
Also 1 letter words go into an loop..
(setq a "This is an X")
(setq b "This is an Y")
...

uncoolperson

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #8 on: December 15, 2006, 06:18:08 PM »
WOW, I'm truly impressed, nice work...

just wait till se7en does this in one line



here it is, the third arg is order mattering (i think it works like that...)

the fourth is to designate how many characters of accuracy are needed to be a 'match'

again i really do believe someone else here can make something neater, but this is my simple while i work shot.

Code: [Select]
_$ (setq a "This is an X")(setq b "This is an Y")(compfun a b nil 1)
"This is an X"
"This is an Y"
((T "This is an ") (nil "X") (nil "Y"))
_$ (setq b "this is a X test")(setq a "test this isn't")(compfun a b nil 1)
"this is a X test"
"test this isn't"
((T "est") (nil "his is a X t") (T "t") (nil " this isn't"))
_$ (setq b "this is a X test")(setq a "test this isn't")(compfun a b nil 2)
"this is a X test"
"test this isn't"
((T "test") (nil "this is a X ") (nil " this isn't"))
_$ (setq b "this is a X test")(setq a "test this isn't")(compfun a b t 2)
"this is a X test"
"test this isn't"
((nil "this is a X ") (T "test") (nil " this isn't"))
_$


Code: [Select]
(DEFUN compfun (string1 string2 ordermatters matchyness / next retlist startmis tempstr swap backwards)
  (WHILE (AND (> (STRLEN string1) matchyness)
      (> (STRLEN string2) matchyness)
)
    (SETQ startmis (VL-STRING-MISMATCH string1 string2))
    (IF (> startmis (1- matchyness))

      (SETQ retlist (APPEND (LIST
      (LIST T
    (IF backwards
      (VL-LIST->STRING
(REVERSE
  (VL-STRING->LIST (SUBSTR string1 1 startmis))
)
      )
      (SUBSTR string1 1 startmis)
    )
      )
    )
    retlist
    )
    string1 (SUBSTR string1 (+ 1 startmis))
    string2 (SUBSTR string2 (+ 1 startmis))
      )
    )

    (SETQ next (VL-STRING-SEARCH (SUBSTR string1 1 matchyness) string2))
    (IF (> next 0)
      (SETQ retlist (APPEND (LIST
      (LIST f
    (IF backwards
      (VL-LIST->STRING
(REVERSE (VL-STRING->LIST (SUBSTR string2 1 next))
)
      )
      (SUBSTR string2 1 next)
    )
      )
    )
    retlist
    )
    string2 (SUBSTR string2 (+ next 1))
      )
      (IF (or swap ordermatters)
(SETQ tempstr string1
      string1 string2
      string2 tempstr
      swap    nil
)
(SETQ string1 (VL-LIST->STRING
  (REVERSE (VL-STRING->LIST string1))
)
      string2 (VL-LIST->STRING
  (REVERSE (VL-STRING->LIST string2))
)
      retlist (REVERSE retlist)
      backwards (= backwards nil)
      swap T
)
      )
    )
  )
  (VL-REMOVE '(nil "")
     (VL-REMOVE '(nil nil)
(APPEND (IF (not backwared)
  (REVERSE retlist)
  retlist
)
(LIST (LIST nil
    (IF backwards
      (VL-LIST->STRING
(REVERSE (VL-STRING->LIST string1))
      )
      string1
    )
      )
      (LIST nil
    (IF backwards
      (VL-LIST->STRING
(REVERSE (VL-STRING->LIST string2))
      )
      string2
    )
      )
)
)
     )
  )
)

uncoolperson

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #9 on: December 15, 2006, 06:23:29 PM »
that one is even more prone to going bad...

sorry, maybe use it as a starting point (or an example of what not to do)

beer:30 pm!

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #10 on: December 15, 2006, 06:45:53 PM »
Yeah, that one turned out tougher then i thought. I got a small recursive procedure to work, but then i noticed a MAJOR flaw. (It would only work if the strings were in exact order.) *lol*

We'll have to play arround with this topic on monday.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

BazzaCAD

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #11 on: December 15, 2006, 11:58:41 PM »
Actually if it makes things easier, I only need it to compare in 1 direction not both.
I.E. a --> b, not a <--> b

So:
(setq a "This is a X test")
(setq b "This isn't a test")
(StrCompare a b)

Would still be:
("This is" "n't" " a test")

Or anther way to think of it would be to only look for additions & changes, not for deletions...
So "n't" was added to the second string & the "X" was deleted...

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #12 on: December 16, 2006, 12:16:24 PM »
yeah, i got it but a one way compairison is still a lot of processing. Lets try and hash out some Pseudo code (Which is prolly really dangerous seeing as i havent even poured myself a cup of coffee yet.)

Code: [Select]
Compare two lists; pseudo code:
[]  given two lists.
o  pop off first item from each list.
o  take item 1 (i1) and compaire it with item 2 (i2)
~  if eq return i1
--  assemble or append new list
# Now this is where things get hairy. We can
# go in two diff. directions

# direction 1 (`Sofar' equality.)
# check existance of equality of list two with
# list one
# verified --e.g.
# ``This is a test''
# ``This isnt a test''
#        ^ Repeated chars `is' and the `is' from `isnt'
#          but since list one has this double char instance
#          as well it is equal sofar.
# This method requires us to cotinualy back trace and dep.
# on how far we back trace our process call doubled or trippled.
# This method would allow us to potentialy create a ``smarter''
# check. -e.g. (``isnt'' diff from ``is'') (no instace of ``X'')
# or the stuff you requested (+ of ``nt'' in list two)
# (- ``X'' in list 2)

# THIS IS SOME BIG CODE


# direction 2 (`Exact match')
# check for exact equality
# this method would result in a ``dumber'' return.
# ``This is a X test''
# ``This isnt a X test''
#          ^ Every thing after this point is diff.
#            so the rest of this string would be returned.
# However in this instace:
# ``This is a X test''
# ``This isnt a test''
#          ^^ ^ Are all differences and would be returned.
# This method requires a more exact string to get results you
# requested.

# THIS IS SIMPLE RECURSIVE CODE.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Joe Burke

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #13 on: December 17, 2006, 01:06:42 PM »
Personally I think once you cross-post the same question here and in the Autodesk customization NG, you don't deserve an answer. Because you are assuming your question is more important than the time and effort wasted in the process by others.

Frankly, I'm sick of seeing cross-posts. There no point reading here if most of what I see is a regurgitation of what I read elsewhere.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #14 on: December 17, 2006, 06:02:48 PM »

There are only a couple of people who do it  Joe ... doesn't take long to learn which posts to ignore.

... but it's a pity we won't see you again :-(


 
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.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #15 on: December 17, 2006, 06:49:50 PM »
Quote
Insert Quote
Personally I think once you cross-post the same question here and in the Autodesk customization NG, you don't deserve an answer. Because you are assuming your question is more important than the time and effort wasted in the process by others.

Frankly, I'm sick of seeing cross-posts. There no point reading here if most of what I see is a regurgitation of what I read elsewhere.



To suggest that this post does not deserve an answer is ludicrous. I myself use the this site as a learning tool, to learn from others as well as the many pros here. I do not use any other NG or site so I can't speak about that. But let's just all get along and not bash someone for posting a duplicate post that may appear on other sites. Just a thought!! :laugh:
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8766
  • AKA Daniel
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #16 on: December 17, 2006, 09:47:17 PM »
I was thinking this would make a fun "Contest" :-)


Dan

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #17 on: December 17, 2006, 11:03:17 PM »
Personally I think once you cross-post the same question here and in the Autodesk customization NG, you don't deserve an answer. Because you are assuming your question is more important than the time and effort wasted in the process by others.

Frankly, I'm sick of seeing cross-posts. There no point reading here if most of what I see is a regurgitation of what I read elsewhere.

There are only a couple of people who do it  Joe ... doesn't take long to learn which posts to ignore.

... but it's a pity we won't see you again :-(

I dont like it either, but i think its funny to watch what posts are answered here and not on other sites. I watch them look and stair while i watch people here embrass the challange. I think it just goes to show the ``level of company'' here.  People get answers here.

Thank you everyone for what you give.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Arizona

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #18 on: December 18, 2006, 04:55:31 AM »
I was thinking this would make a fun "Contest" :-)


Hehe...  :-)

BazzaCAD

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #19 on: December 18, 2006, 11:53:17 AM »
Personally I think once you cross-post the same question here and in the Autodesk customization NG, you don't deserve an answer. Because you are assuming your question is more important than the time and effort wasted in the process by others.

Frankly, I'm sick of seeing cross-posts. There no point reading here if most of what I see is a regurgitation of what I read elsewhere.

There are only a couple of people who do it  Joe ... doesn't take long to learn which posts to ignore.

... but it's a pity we won't see you again :-(

I dont like it either, but i think its funny to watch what posts are answered here and not on other sites. I watch them look and stair while i watch people here embrass the challange. I think it just goes to show the ``level of company'' here.  People get answers here.

Thank you everyone for what you give.


I used to read & post in the Autodesk NG all the time, but I started to find the people in there rude & unhelpful, so I started to ignore it. I know this question would be a hard one to solve so I gave the Autodesk NG a second chance. As you can see I didn't get any replays tell late yesterday, but had 10 or so replays here in just a few hours after my first post. I find this NG much more friendly & helpful to it's members, unless people like yourself start posting unhelpful comments like yours. So I'm going to stop posting in the Adesk NG & you can go ahead & hang out with the unhelpful people over there.

thx to everyone else that has been helpful in trying to figure out my problem.





Arizona

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #20 on: December 18, 2006, 12:10:23 PM »

I used to read & post in the Autodesk NG all the time, but I started to find the people in there rude & unhelpful, so I started to ignore it. I know this question would be a hard one to solve so I gave the Autodesk NG a second chance. As you can see I didn't get any replays tell late yesterday, but had 10 or so replays here in just a few hours after my first post. I find this NG much more friendly & helpful to it's members, unless people like yourself start posting unhelpful comments like yours. So I'm going to stop posting in the Adesk NG & you can go ahead & hang out with the unhelpful people over there.

thx to everyone else that has been helpful in trying to figure out my problem.
Bazzacad,
This is not a NG, this is a community.  :-)
And like any community, you have some people that are willing to "lend a hand" (this is what makes theswamp such a great place) and then you have others that can't remember what it's like to ask questions (Hmmm...Is this because they know it all?). Asking questions (without fear of rude answers) is part of what has made theswamp such a wonderful place. So ask away... And BTW, Welcome to the Swamp!

BazzaCAD

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #21 on: December 18, 2006, 12:56:01 PM »
This is not a NG, this is a community.  :-)

Oops, sorry you're right, this is a great community.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #22 on: December 18, 2006, 01:02:39 PM »
And like any community, you have some people that are willing to "lend a hand" (this is what makes theswamp such a great place) and then you have others that can't remember what it's like to ask questions (Hmmm...Is this because they know it all?). Asking questions (without fear of rude answers) is part of what has made theswamp such a wonderful place. So ask away... And BTW, Welcome to the Swamp!
The issue isn't with asking a question, it is about asking the same question in two different places.  I feel the same as Joe and Kerry, and find myself not wanting to answer questions posted by these people.  If it only happens once or twice its cool with me, but if it becomes a constant theme, then I won't answer the questions.

Hope that clears up what the issue is/was.
Tim

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

Please think about donating if this post helped you.

Arizona

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #23 on: December 18, 2006, 05:03:02 PM »
However, this feedback (about dual posting) could have been provided in a constuctive manner. Since not everyone knows what offends someone else it would have been more appropriate to send the person a PM and tell them in private or do like Greg did in this thread and find a nice way of explaining things without coming across sounding...uh..that way.

JMO :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #24 on: December 18, 2006, 05:14:58 PM »
I'm outa here .
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #25 on: December 18, 2006, 05:26:50 PM »
True it could have been said in a less aggressive way.

I hope both people will remain at theswamp, and continue to ask/answer questions.
Tim

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

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #26 on: December 18, 2006, 05:29:53 PM »
Tim, I suggest you go back and re-read what I said.
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #27 on: December 18, 2006, 05:38:22 PM »
Tim, I suggest you go back and re-read what I said.
I don't think anyone had a problem with your post Kerry, only Joe's.  At least that is what I'm going on.

And I hope Joe doesn't leave, as he has been a good person to bounce ideas off of, and get some great routines and help from.  I value him as a friend and a resource.
Tim

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

Please think about donating if this post helped you.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #28 on: December 18, 2006, 06:39:34 PM »
Personally I think once you cross-post the same question here and in the Autodesk customization NG, you don't deserve an answer. Because you are assuming your question is more important than the time and effort wasted in the process by others.

Frankly, I'm sick of seeing cross-posts. There no point reading here if most of what I see is a regurgitation of what I read elsewhere.

Joe, while I can appreciate your candor and point of view regarding cross-posting, you should be aware that theswamp has absolutely nothing at all to do with the Autodesk news groups. In fact, I think you will find that many of the visitors to theswamp rarely if ever visit the Autodesk NG.
The reason you might find that true, is because here at theswamp, we pride ourselves on being at least a little bit civilized (unlike the NG's) and we don't tolerate flaming. The mere fact that something was posted elsewhere on the internet does not constitute cross-posting. In fact, if you were to do a web search using just about any search engine on just about any topic, you will find hundreds if not thousands of nearly identical problems and posts to bulletin boards and forums all over the internet. Now that is not to say that we condone defacto cross posting, in fact, if there is identical posts (or nearly identical) by the same person, we as moderators and admins will do our best to remove the one posted in the incorrect place or move it to the correct forum. This is where you can help. In the future if there is a cross-posted topic (or off topic post for that matter) all you need to do is select the "report to moderator" link and we will be glad to review the post in question and take whatever action is deemed necessary.
Thanks for you participation and help in making this the fine place it is.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

BazzaCAD

  • Guest
Re: Compare 2 strings & return a list of strings with the differences?
« Reply #29 on: December 22, 2006, 03:12:58 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...

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.