Author Topic: Alphabet character string only  (Read 12828 times)

0 Members and 1 Guest are viewing this topic.

XXL66

  • Newt
  • Posts: 99
Alphabet character string only
« on: April 08, 2018, 05:29:07 AM »
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...
« Last Edit: April 08, 2018, 05:34:28 AM by XXL66 »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Alphabet character string only
« Reply #1 on: April 08, 2018, 06:09:19 AM »
If I remember correctly Roy wrote some functions 'FullyAlphabetic' / 'FullyNumeric'.. and so on, but I'm unable to find that thread.

Anyway:
Code: [Select]
; _$ (StrNump "abcdefg") -> nil
; _$ (StrNump "abcdef8g") -> T
(defun StrNump ( s )
  (if (/= s "")
    (or
      (wcmatch (substr s 1 1) "#")
      (StrNump (substr s 2))
    )
  )
)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Dlanor

  • Bull Frog
  • Posts: 263
Re: Alphabet character string only
« Reply #2 on: April 08, 2018, 06:10:27 AM »
Depends on your Alphabet  :thinking:

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Alphabet character string only
« Reply #3 on: April 08, 2018, 06:40:31 AM »
Code: [Select]
(defun alpha-p ( s ) (wcmatch s "~*[~A-Za-z]*"))

XXL66

  • Newt
  • Posts: 99
Re: Alphabet character string only
« Reply #4 on: April 08, 2018, 07:36:20 AM »
 8-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Alphabet character string only
« Reply #5 on: April 08, 2018, 09:50:12 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun AlphaOnly (s)
  2.     '(lambda (x) (< 64 x 91))
  3.     (vl-string->list (strcase s))
  4.   )
  5. )
  6.  
  7. (defun DigitOnly (s)
  8.     '(lambda (x) (< 64 x 91)))
  9.     (vl-string->list s)
  10.   )
  11. )
Speaking English as a French Frog

Dlanor

  • Bull Frog
  • Posts: 263
Re: Alphabet character string only
« Reply #6 on: April 08, 2018, 09:54:13 AM »
Code: [Select]
(defun AlphabetOnly ($ /)
  (while (and (wcmatch (substr $ 1 1) "@") $)
    (setq $ (substr $ 2))       
  )
  (= $ "")
)

Code: [Select]

(defun alpha-p ( s ) (wcmatch s "~*[~A-Za-z]*"))


Neither account for a string with a space or spaces

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Alphabet character string only
« Reply #7 on: April 08, 2018, 10:16:02 AM »
Neither account for a string with a space or spaces

Where did the OP state the requirement to permit spaces?

Dlanor

  • Bull Frog
  • Posts: 263
Re: Alphabet character string only
« Reply #8 on: April 08, 2018, 11:27:42 AM »
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #9 on: April 08, 2018, 11:34:44 AM »
Neither account for a string with a space or spaces

A space is not an alphabetic character.

i was merely pointing out that feeding in a string of only alphabet characters would return nil if there was a space

As they should.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Dlanor

  • Bull Frog
  • Posts: 263
Re: Alphabet character string only
« Reply #10 on: April 08, 2018, 11:41:04 AM »
A space is not an alphabetic character.

I agree, but it denotes no alphabet character, otherwiseitwouldmakereadingtextstringsmoredifficult.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #11 on: April 08, 2018, 11:45:03 AM »
completelyirrelevant
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #12 on: April 08, 2018, 12:43:11 PM »
Back on track, want to say that:

(defun alpha-p (s) (wcmatch s "~*[~A-Za-z]*"))

And it's obvious companions like:

(defun digits-p (s) (wcmatch s "~*[~0-9]*"))

Are very elegant solutions. Nicely done Lee.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Alphabet character string only
« Reply #13 on: April 09, 2018, 03:26:34 PM »
I don't see how it cannot be relevant.

Yes, when building a parser/etc. typically you often only use [A-Za-z] (or [:alpha:] in posix terms) and parse out other language structures separately (that's they way I've always done my parsing) but that doesn't make the request irrelevant.

If you want spaces just add it to the regex list.
Code - Auto/Visual Lisp: [Select]
  1. (defun alpha-p(s) (wcmatch s "~*[~A-Za-z],[ ]*"))

Code: [Select]
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
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Alphabet character string only
« Reply #14 on: April 09, 2018, 03:44:35 PM »
Why stop there, you might as well pen goofy flavours of listp, minusp, numberp etc. while you’re at it.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst