Jump to content

Autolisp function that returns the missing members of a string compare?


Recommended Posts

Posted

Hello all,

Does anyone know of a lisp function that will take two strings and return the missing elements of the compare as strings? 

For instance to compare "123410" and "12310" and return "4" or compare "123410" and "310" and return "1" "2" "4"?

 

Before I jump off and try and write a bunch of redundant code, I tried a search and came up empty, but I have seen some very interesting functions pop up here.

 

Thanks!

GregSS

Posted

Well, pBe I am going to use vl-string-mismatch to put in the function, but what that returns is really the number of characters that match, or the position where they stop matching, though it cannot get far enough to figure out if they later have characters that do match...so "123456789"  "123589" will return 3 but not allow the return of the Missing pieces which are "4" "6" "7".

So I am off making funtions.

 

Thank you!

GregSS

Posted

Because we can 🙂

(Defun _mismatchsocks (s1 s2 / s)
  (while (< (Setq p (Vl-string-mismatch s1 s2))
	    (strlen s1))
    (setq s (cons (substr s1 (1+ p) 1) s))
    (setq s2 (strcat (substr s1 1 (1+ p))
		     (substr s2 (1+ p))
	     )
    )
  ) (reverse s)
)

 

_$ (_mismatchsocks "123410" "12310")
("4")
_$ (_mismatchsocks "123410" "310" )
("1" "2" "4")
_$ (_mismatchsocks "123456789" "123589")
("4" "6" "7")

(_mismatchsocks "CADTUTOR" "CDTTOR")

("A" "U")

 

But then again, that's jsut one way of doing it. 

Just wait,  others post with another way of achieving the same results

 

Cheers

 

 

 

 

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...