GregSS Posted June 28, 2021 Posted June 28, 2021 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 Quote
GregSS Posted June 28, 2021 Author Posted June 28, 2021 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 Quote
pBe Posted June 29, 2021 Posted June 29, 2021 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 1 Quote
Recommended Posts
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.