shakuhachi Posted August 24, 2011 Share Posted August 24, 2011 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! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2011 Share Posted August 24, 2011 (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" Quote Link to comment Share on other sites More sharing options...
shakuhachi Posted August 24, 2011 Author Share Posted August 24, 2011 That was quick. Thanks again Lee! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 24, 2011 Share Posted August 24, 2011 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 Quote Link to comment Share on other sites More sharing options...
shakuhachi Posted August 24, 2011 Author Share Posted August 24, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.