Jump to content

case sensitivity


kalai

Recommended Posts

Tech you don't need to split up numbers and letters. But I just liked how it looked. so you don't really even need to test for anything. The lisp below just puts each char in brackets and works the same.

 

;;----------------------------------------------------------------------------;;
;; Generate a text search that ignores Case Senesitivity.
;; saunambon654, Lee Mac, mhupp
;; https://www.cadtutor.net/forum/topic/39880-case-sensitivity/#comment-618863 
;; (ssget "X" (list '(0 . "TEXT") (cons 1 (IC "Floor9")))) 
;; (ssget "X" '((0 . "TEXT") (1 . "[Ff][Ll][Oo][Oo][Rr][99]"))) 
(defun IC (str1 / str2 i) 
  (if (= (type str1) 'STR) 
    (progn 
      (setq str2 "" i 1) 
      (repeat (strlen str1) 
        (setq x (substr str1 i 1))
        (setq str2 (strcat str2 "[" (strcase x) (strcase x T) "]")) 
        (setq i (1+ i))
      )
    )
  )
  str2
)

 

So this would generated (ssget "X" '((0 . "TEXT") (1 . "[Ff][Ll][Oo][Oo][Rr][99]"))) It would find all values for Floor9, but not Floor99.

 

 

 

 

 

Edited by mhupp
Link to comment
Share on other sites

1 minute ago, mhupp said:

Tech you don't need to split up numbers and letters. But I just liked how it looked. so you don't really even need to test for anything. The lisp below just puts each char in brackets and works the same.

 

;;----------------------------------------------------------------------------;; 
;; Generate a text search that ignores Case Senesitivity. 
;; saunambon654, Lee Mac, mhupp 
;; https://www.cadtutor.net/forum/topic/39880-case-sensitivity/#comment-618863 
;; (ssget "X" (list '(0 . "TEXT") (cons 1 (IC "Floor9")))) 
;; (ssget "X" '((0 . "TEXT") (1 . "[Ff][Ll][Oo][Oo][Rr][99]"))) 
(defun IC (str1 / str2 i) ;ignore case
  (if (= (type str1) 'STR) 
    (progn 
      (setq str2 "" i 1) 
      (repeat (strlen str1) 
        (setq str2 (strcat str2 "[" (strcase x) (strcase x T) "]"))) 
        (setq i (1+ i))
      )
    )
  )
  str2
)

 

So this would generated (ssget "X" '((0 . "TEXT") (1 . "[Ff][Ll][Oo][Oo][Rr][99]"))) It would find all values for Floor9, but not Floor99.

 

 

 

 

 

Of course you could do it, we just find the best way. If your string is long (hundreds of letters) it will be effect to speed calculation.

Link to comment
Share on other sites

Here's another way to write it -

(defun casesensitivity ( s )
    (vl-list->string
        (apply 'append
            (mapcar '(lambda ( a b ) (if (= a b) (list a) (list 91 a b 93)))
                (vl-string->list (strcase s))
                (vl-string->list (strcase s t))
            )
        )
    )
)

 

As for combinations, maybe something like this -

(defun combinations ( s / foo )
    (defun foo ( u l )
        (if (cdr u)
            (append
                (mapcar '(lambda ( x ) (cons (car u) x)) (foo (cdr u) (cdr l)))
                (mapcar '(lambda ( x ) (cons (car l) x)) (foo (cdr u) (cdr l)))
            )
            (list u l)
        )
    )
    (mapcar 'vl-list->string
        (foo
            (vl-string->list (strcase s))
            (vl-string->list (strcase s t))
        )
    )
)
_$ (length (combinations "floor"))
32

 

  • Like 3
Link to comment
Share on other sites

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...