(defun AlphabetOnly ($ /)
(while (and (wcmatch (substr $ 1 1) "@") $)
(setq $ (substr $ 2))
)
(= $ "")
)
; _$ (StrNump "abcdefg") -> nil
; _$ (StrNump "abcdef8g") -> T
(defun StrNump ( s )
(if (/= s "")
(or
(wcmatch (substr s 1 1) "#")
(StrNump (substr s 2))
)
)
)
(defun alpha-p ( s ) (wcmatch s "~*[~A-Za-z]*"))
(defun AlphabetOnly ($ /)
(while (and (wcmatch (substr $ 1 1) "@") $)
(setq $ (substr $ 2))
)
(= $ "")
)
(defun alpha-p ( s ) (wcmatch s "~*[~A-Za-z]*"))
Neither account for a string with a space or spaces
Where did the OP state the requirement to permit spaces?
Neither account for a string with a space or spaces
i was merely pointing out that feeding in a string of only alphabet characters would return nil if there was a space
A space is not an alphabetic character.
Command: (defun alpha-p (s) (wcmatch s "~*[~A-Za-z],[ ]*"))
ALPHA-P
Command: (alpha-p "test")
T
Command: (alpha-p "123")
nil
Command: (alpha-p "this is a big long string")
T
Command: (alpha-p "this is a big long string with numbers 123")
nil
Why stop there, you might as well pen goofy flavours of listp, minusp, numberp etc. while you’re at it.What (I'm confused)? ...No. But I don't see how the addition of spaces was all that big of a deal--as far as requests go--or that far out of possibilities -i.e. a user wanting to quickly check the string is of only alpha and spaces with a high level language (a language which doesn't treats strings as arrays). I'm confused (that elevated quickly).
@John:Sure. That'll work.
You probably mean:Code - Auto/Visual Lisp: [Select]
An isalpha predicate function that allows non alpha characters is illogical.yep, and it returns nil for the Alpha itself :)
returns nil for the Alpha itself :)
(alpha-p "α")
@John:
You probably mean:Code - Auto/Visual Lisp: [Select]
I just added a space to Lee's suggestion in response to John's attempt (which does not work properly).@John:
You probably mean:Code - Auto/Visual Lisp: [Select]
Was that yours Roy? Very neat work!
Excuse my ignorance, why?An isalpha predicate function that allows non alpha characters is illogical.yep, and it returns nil for the Alpha itself :)
(alpha-p "α")
I just added a space to Lee's suggestion in response to John's attempt (which does not work properly).@John:
You probably mean:Code - Auto/Visual Lisp: [Select]
Was that yours Roy? Very neat work!
Command: (defun a (s) (wcmatch s "~*[~A-Za-z ]*"))
A
Command: (a "test")
T
Command: (a "a")
T
Command: (a ".")
nil
Command: (defun b (s) (wcmatch s "~*[~A-Za-z],[ ]*"))
B
Command: (b "test")
T
Command: (b "a")
T
Command: (b ".")
nil
Excuse my ignorance, why?
Comando: (ascii "α") 92
Comando: (chr 92) "\\"
Comando: (ascii "\\") 92
Code - Auto/Visual Lisp: [Select]
_$ (a "1a") nil _$ (b "1a") T
I have: Code page 850 (Latin-1 - Western European languages)Excuse my ignorance, why?
Comando: (ascii "α") 92
Comando: (chr 92) "\\"
Comando: (ascii "\\") 92
That's odd. If I'm not mistaken, Portuguese is your natural language and Portuguese uses cp850 or cp860 but only the extended char set in those differs from the std char set.
https://www.ascii-codes.com/cp860.html
Weird! If you figure that one out, let me know (you have peeked my interest).
(ascii "a") returns 97 in both Autocad 2018 and BricsCAD 18.2(ascii "α")
this is all about UnicodeExcuse my ignorance, why?An isalpha predicate function that allows non alpha characters is illogical.yep, and it returns nil for the Alpha itself :)
(alpha-p "α")
Comando: (ascii "α") 92
Comando: (chr 92) "\\"
Comando: (ascii "\\") 92
...Maybe this was correct:
this is all about Unicode
and that's why functions like alpha-p have to be unique for every language/locale
Depends on your Alphabet :thinking:
I think this should do the trick or is there another/easier method available with VL-string functions?Just a new start:
(defun foo (s)
(and
(/= "" s)
(=
(vl-string-translate
" !\"#$%&'()*+,-./123456789:;<=>?@[\\]^_`{|}~"
"0000000000000000000000000000000000000000000"
s
)
s
)
(not (distof s));Edit3
)
)
(foo "abc ") nil
(foo "abc" ) T
(foo "a" ) nil
(foo "." ) nil
(foo "1.2" ) nil
(foo "a.b" ) nil
(foo "a b" ) nil
(foo "" ) nil
(foo "0" ) nil
... the op wanted a find a space and alpha chars ...
I think this should do the trick or is there another/easier method available with VL-string functions?Code: [Select](defun AlphabetOnly ($ /)
(while (and (wcmatch (substr $ 1 1) "@") $)
(setq $ (substr $ 2))
)
(= $ "")
)
Edit: should still check "" input...
#include <ctype.h>
isalpha()
isspace()
isalnum()
ispunct()
... much of the autolisp community is in trouble.
I'm not angry and the OP has no alpha spaces problem to solve.*facepalm* (re-scans thread) ...I think I understand, now, where I got tossed off track.
Where did the OP state the requirement to permit spaces?
He didn't, i was merely pointing out that feeding in a string of only alphabet characters would return nil if there was a space, whereas Grr1337's wouldn't.
(defun foo (s)
(and
(/= "" s)
(not (vl-string-position (ascii "0") s))
(=
(vl-string-translate
" !\"#$%&()*+,/123456789:;<=>?@[\\]^_`{|}~"
"0000000000000000000000000000000000000000"
s
)
s
)
)
)
(foo "abc" )T
(foo "a" )T
(foo "Marc'Antonio")T
(foo "Marco-Antonio")T
(foo "MarcAntonio.")T
(foo "a.b" )T
(foo "." )T
(foo "abc ")nil
(foo "1.2" )nil
(foo "a b" )nil
(foo "" )nil
(foo "0" )nil
(foo "0.0" )nil
(foo "a0.0")nil
(foo "-1" )nil
(foo ".1" )nil
(defun MyCyrillicAlphabet ( / s x )
(setq s "")
(setq x 256)
(while (<= 192 (setq x (1- x)) 255)
(setq s (strcat (chr x) s))
)
(strcat s " ")
)
_$ (DependsOnYourAlphabet "This is not my alphabet" (MyCyrillicAlphabet)) >> nil
_$ (DependsOnYourAlphabet "Това е моята азбука" (MyCyrillicAlphabet)) >> T
Thinking off topic :
Just thinking about alphabetic punctuation ... just 'cause ...
The hyphen is interesting ; could be considered ( or used as ) a minus sign and exponent.
We would need to build in some interesting test cases for hyphenated characters.
Ditto Full-Stop and the decimal marker.
... and that's without the usage of special characters in some languages ...
Just for fun:I'm not an expert so I do not make judgments about it, but I think it's better to exclude all non-alphabetic characters than to include numerical ones.Code: [Select]...
_$ (DependsOnYourAlphabet "This is not my alphabet" (MyCyrillicAlphabet)) >> nil
_$ (DependsOnYourAlphabet "Това е моята азбука" (MyCyrillicAlphabet)) >> T
(foo "Yaoundé") => T
(DependsOnYourAlphabet "Yaoundé" "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz -_.'") => nil
(DependsOnYourAlphabet "Yaoundé" "éAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz -_.'")
Did not read this whole thread, but this is what first came to my mind:Is similar:Code - Auto/Visual Lisp: [Select]
"a.b" "." "abc " "1.2" "a b" "" "0" "0.0" "a0.0" "-1" ".1" "Yaoundé" ) ) ;;(("abc" T) ("a" T) ("Marc'Antonio" T) ("Marco-Antonio" T) ("MarcAntonio." T) ("a.b" T) ("." T) ("abc " T) ("1.2" nil) ("a b" T) ("" T) ("0" nil) ("0.0" nil) ("a0.0" nil) ("-1" nil) (".1" nil) ("Yaoundé" T))
;gile
(defun AlphaOnly (s)
(vl-every
'(lambda (x) (< 64 x 91))
(vl-string->list (strcase s))
)
)
("abc " T) ("a b" T) ("" T)Null strings or spaces appear not to be allowed. :)
:) :tickedoff: 8)Null strings or spaces appear not to be allowed. :)
That was answered here (http://bit.ly/2JE2GPQ).
Just for fun:Comando: (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")Code: [Select](defun DependsOnYourAlphabet ( Str MyAlphabet )
(
(lambda ( f s a )
(if (/= s "")
(f s a)
)
)
(lambda ( s a )
(or (= s "")
(and
(vl-string-search (substr s 1 1) a)
(f (substr s 2) a)
)
)
)
Str MyAlphabet
)
); defun DependsOnYourAlphabet
...
_$ (DependsOnYourAlphabet "Това е моята азбука" (MyCyrillicAlphabet)) >> T
Comando: (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
0
Comando: (substr "Това е моята азбука" 1 1)
"\\"
_$ (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
2
_$ (substr "Това е моята азбука" 1 1)
"Т"
Null strings or spaces appear not to be allowed. :)
That was answered here (http://bit.ly/2JE2GPQ).
Ok, thanks for test. :)Comando: (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
0
Comando: (substr "Това е моята азбука" 1 1)
"\\"
Everythings fine on my end:Code: [Select]_$ (vl-string-search (substr "Това е моята азбука" 1 1) "е Това е моята азбука")
2
_$ (substr "Това е моята азбука" 1 1)
"Т"
Maybe you have the same issue as I'm having with the Spanish alphabet - VLIDE doesn't recognise these characters.
; by Grrrr1337 (modified see: < not)
; (setq NotAlpha " !\"#$%&()*+,/0123456789:;<=>?@[\\]^_`{|}~")
; (String_AlphaP "Yaoundé" NotAlpha)
(defun String_AlphaP ( Str NotAlpha )
(
(lambda ( f s a )
(if (/= s "")
(f s a)
)
)
(lambda ( s a )
(or (= s "")
(and
(not (vl-string-search (substr s 1 1) a)); < not
(f (substr s 2) a)
)
)
)
Str NotAlpha
)
)
:-)
Maybe you have the same issue as I'm having with the Spanish alphabet - VLIDE doesn't recognise these characters.VLIDE (unlike Autocad Text Window) does not support Unicode, so it recognizes only those characters that belong to your local code page.
:) :tickedoff: 8)
I'm wondering how this doesn't have billions (http://www.youtube.com/watch?v=u_aLESDql1U) previews, Michael. :)
Sorry if I do not comment but I would not misunderstand the "Canadian" irony... it happens that in a different language the same thing has a different meaning.:) :tickedoff: 8)
uh huh
; (setq NotAlpha " !\"#$%&()*+,/0123456789:;<=>?@[\\]^_`{|}~")
; (ALE_String_AlphaP "Yaoundé" NotAlpha)
;
(defun ALE_String_AlphaP (s n / f)
(defun f (s n)
(cond
( (= s "") )
( (and (not (vl-string-search (substr s 1 1) n)) (f (substr s 2) n)) )
)
)
(cond ( (= s "") nil ) ( (f s n) ))
)
;variante con IF
(defun ALE_String_AlphaP (s n / f)
(defun f (s n)
(if (/= s "")
(and
(not (vl-string-search (substr s 1 1) n))
(f (substr s 2) n)
)
T
)
)
(and (/= s "") (f s n))
)
Sorry if I do not comment but ...