Jump to content

EQ, =, EQUAL but NOT case sensitive...?


Recommended Posts

Posted

Hey guys,

 

I have a routine which is comparing and updating the revision value in our title blocks, and have found that there is a need to consider some values equal or not... but ignoring the case of the character.

 

For example, I would like the routine to consider 'A' and 'a' to be equal.

 

I have found this thread at Stack Overflow: http://stackoverflow.com/questions/547436/whats-the-difference-between-eq-eql-equal-and-equalp-in-common-lisp

 

... which suggests the use of "equalp". But it seems "equalp" is not an AutoLISP function.

 

Is there any substitute for "equalp" in AutoCAD?

 

Thanks a lot for any help.

Posted

You can force the string to uppercase at the time of comparison.

 

(setq s1 "lamensterms"  s2 "Lamensterms") (eq (strcase s1)(strcase s2))

 

Will that be enough for your needs?

Posted

Hi pBe,

 

Thanks a lot for the reply. I'm not sure that the code you have provided can be applied to the routine (at least, maybe not the way I current have the code structured).

 

My current (partial) code is:

 

 ((= crev "A")
  (SETQ nrev "B"))
((= crev "B")
  (SETQ nrev "C"))
((= crev "C")
  (SETQ nrev "D"))

 

Where "crev" is the current revision, extracted from an attribute within the revision block, and "nrev" is the new revision to be set.

 

Any lower case revision letters would be typos, I don't really need to correct the case of the existing revisions... but I would like the routine to be able to read the value regardless of the case - if that makes sense.

 

So if crev = A, nrev = B. And if crev = a, nrev = B. And so on..

 

I could simply add the following lines to my routine:

 

 ((= crev "a")
  (SETQ nrev "B"))
((= crev "b")
  (SETQ nrev "C"))
((= crev "c")
  (SETQ nrev "D"))

 

But I was just curious if there was another way, with a less strict "=" function.

Posted

I see,

 

(if (setq a (assoc (strcase crev) '(("A" "B") ("B" "C") ("C" "D")("D" "E"))))
 (setq nrev (cadr a))
)

 

Now what if the value or CREV is not defined on the list? "E" for example , and like you said, typos like "A "

 

or even better

 

(chr (1+ (Ascii (strcase crev ))))

Posted

As for string comparison: Here's a quick and dirty code [for the fun of it]

 

(defun _equalstr (s1 s2)
 (wcmatch s1
   (apply 'strcat
	  (mapcar '(lambda (x)
		     (if (<= 65 x 90)
		       (strcat "[" (chr x) (chr (+ 32 x)) "]")
		       (chr x)
		     )
		   )
		  (vl-string->list (strcase s2))
	  )
   )
 )
)

 

(_equalstr "CADTutor-here" "CADTUTOR-Here")

(_equalstr "The quick brown FOX jumps over the lazy dog" "The Quick Brown Fox Jumps Over The Lazy Dog")

 

But of course, its loads easier just to use strcase function :)

Posted

Lamensterms, to ensure that your code excerpt works in any case, you may also make sure that crev variable is uppercase before use it in comparison:

[color=magenta](setq crev (strcat crev))[/color]
[color=black]...[/color]
((= crev "A")
  (SETQ nrev "B"))
((= crev "B")
  (SETQ nrev "C"))
((= crev "C")
  (SETQ nrev "D"))

Posted

Ah awesome, thanks for those pointers. I really like the idea of using the 'chr' and 'ascii' functions.

 

I do intend to post the entire code, to get general feedback and corrections. I imagine there will be quite a few adjustments once I get some input from you guys - haha.

 

In the mean time I'll post a few more questions to help me develop the code a bit further (probably best I start new threads though I think).

 

Thanks again pBe.

Posted

Hi Mircea, thanks for the reply and the suggestion - that is a good option I think.

 

Thanks again.

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