Jump to content

Recommended Posts

Posted

Hi,

 

I can get String length by STRLEN but How to determine that String length is even or odd?

 

I want to give different conditions for even and odd stringlength.

 

waiting...

Posted

Got it...

 

Thanks pBe

Posted

Another is number even or oddd ? (if (= (- (/ Numb 2.0) (fix (/ Numb 2.0))) 0.50)) its odd as it will be 0.5 for integers.

Posted (edited)

(logand (strlen str) 1)

;EDIT: integer only

(boole 1 (strlen str) 1)

 

TEST: -10 to 10

((lambda(i)
  (repeat 21 (princ (strcat "\n"(itoa i) " -> " (itoa (Boole 1 i 1)))) (setq i (1+ i)) (princ))
  ) ;_ end of lambda
[color="green"] -10[/color]
 )

 

-10 -> 0

-9 -> 1

...

...

-1 -> 1

0 -> 0

..

..

10 -> 0

Edited by hanhphuc
Posted

Nice one hanhphuc one of those you put away for a rainy day

Posted
Nice one hanhphuc one of those you put away for a rainy day

Thank you sir :)

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