Jump to content

Find text


shakuhachi

Recommended Posts

Hello guys! I'm stuck again and need your help.

 

How can I find the string position of the 1st non-number in a string? I want to extract the text in the string.

 

"1234ASDF" returns 5

"64 ZXC" returns 4 --> not including "space"

"845.25LKJH" returns 7

 

Thanks!

Link to comment
Share on other sites

(defun _extracttext ( s )
   (vl-list->string
       (vl-remove-if-not '(lambda ( x ) (or (< 64 x 91) (< 96 x 123)))
           (vl-string->list s)
       )
   )
)
(vl-load-com)

 

_$ (_extracttext "845.25LKJH")
"LKJH"
_$ (_extracttext "1234ASDF")
"ASDF"
_$ (_extracttext "64 ZXC")
"ZXC"

Link to comment
Share on other sites

Or, to find the position, as you originally asked:

 

(defun _firstalpha ( s / i )
   (setq i 0)
   (vl-some '(lambda ( x ) (setq i (1+ i)) (or (< 64 x 91) (< 96 x 123))) (vl-string->list s))
   i
)

 

_$ (_firstalpha "1234ASDF")
5
_$ (_firstalpha "64 ZXC")
4
_$ (_firstalpha "845.25LKJH")
7

Link to comment
Share on other sites

Thanks Lee, this would come in handy in the future...

 

Or, to find the position, as you originally asked:

 

(defun _firstalpha ( s / i )
   (setq i 0)
   (vl-some '(lambda ( x ) (setq i (1+ i)) (or (< 64 x 91) (< 96 x 123))) (vl-string->list s))
   i
)

 

_$ (_firstalpha "1234ASDF")
5
_$ (_firstalpha "64 ZXC")
4
_$ (_firstalpha "845.25LKJH")
7

Link to comment
Share on other sites

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