Jump to content

Counting text from point in the string


Recommended Posts

Posted

I want to count text but want to start it from a dash in the text. Only thing consistant in the test is the dash.

 

I know strlen to count but do I convert to a list then use member?

examples of string

Cooler - ...

Freezer - ...

Freezer Refrigeration - ...

Posted (edited)

If you're trying to count the number of characters after a - in a string

here's one way... if a - isn't in the string you'll get an error

_4$ (- (strlen "Cooler-123")(vl-string-position (ascii "-") "Cooler-123" 0 ) 1)
3

Edited by lpseifert
Posted

(defun foo (s)
 (vl-string-left-trim
   " "
   (substr s
           (+ 2
              (cond ((vl-string-search "-" s))
                    (-1)
              )
           )
   )
 )
)

 

(foo "alan - thompson") -> "thompson"

(foo "alan") -> "alan"

Posted

Not dissimilar to Alans...

 

(defun foo ( s )
 (vl-string-left-trim " "
   (vl-list->string
     ( (lambda ( l ) (cond ( (cdr (member 45 l)) ) ( l ))) (vl-string->list s) )
   )
 )
)

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