Lt Dan's legs Posted September 2, 2010 Posted September 2, 2010 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 - ... Quote
lpseifert Posted September 2, 2010 Posted September 2, 2010 (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 September 2, 2010 by lpseifert Quote
alanjt Posted September 2, 2010 Posted September 2, 2010 (defun foo (s) (vl-string-left-trim " " (substr s (+ 2 (cond ((vl-string-search "-" s)) (-1) ) ) ) ) ) (foo "alan - thompson") -> "thompson" (foo "alan") -> "alan" Quote
Lee Mac Posted September 2, 2010 Posted September 2, 2010 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) ) ) ) ) Quote
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.