TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on January 05, 2012, 03:13:13 PM
-
hello all and happy new year.
my first request for the new year :-o
can anyone help me with how i can get code to tell the difference between a variable being words or numbers?
example
(if var = a word
(do this)
)
(if var = a number
(do this)
)
any help is appreciated
-
You could check with the type function - if I'm understanding correctly.
Command: (type 3.4)
REAL
Command: (type 3)
INT
Command: (type "3.4")
STR
-
thanks for the reply Alan, however my variables will always be in quotes so it will come up as a string and not an integer
-
Try distof...
Command: (distof "3.4")
3.4
Command: (distof "blah")
nil
-
thanks again but that isnt working either
my number is returned as a string and looks like this
"97 01000 000 16 99 10"
and distof returns nil
-
Give me a few examples to go on - as word and as number.
-
Give me a few examples to go on - as word and as number.
a word, for instance, would be
"plate" or "pipe". just a plain word.
and a number would be
"97 01000 000 16 99 10"
the number would be exactly like you see it here but with different digits
same spacing format.
both would be returned via my existing code as strings
-
A fairly simplistic solution for this specific case:
(if (wcmatch str "*@*")
(princ "\nIt is a string.")
(princ "\nIt is a number")
)
-
just for the single words without digits (not for "cloud number 9" etc):
(if
(vl-some '(lambda(x)
(or (distof (chr x))(eq 32 x)))
(vl-string->List StringExpression))
(alert "number")
(alert "word"))
-
A fairly simplistic solution for this specific case:
(if (wcmatch str "*@*")
(princ "\nIt is a string.")
(princ "\nIt is a number")
)
Nice 8-)
-
A fairly simplistic solution for this specific case:
(if (wcmatch str "*@*")
(princ "\nIt is a string.")
(princ "\nIt is a number")
)
There you go. :-)
Nice 8-)
-
thanks everyone
both solutions work perfectly
didnt think it was that easy... :ugly: