muthu123 Posted July 14, 2010 Posted July 14, 2010 Dear friends, I want to remove the spaces in a particular string by the following code.But it is not returning my requirement. (strcase (vl-string-translate " " "" "8 x 150 x 2974")) returns "8 X 150 X 2974" (strcase (vl-string-translate " " "a" "8 x 150 x 2974")) returns "8AXA150AXA2974" Pls help me in this. Do you know any other than this function? Yours, Muthu. Quote
lpseifert Posted July 14, 2010 Posted July 14, 2010 http://www.cadtutor.net/forum/showthread.php?t=50099 Quote
muthu123 Posted July 14, 2010 Author Posted July 14, 2010 http://www.cadtutor.net/forum/showthread.php?t=50099 Thank you so much. Quote
Hippe013 Posted July 14, 2010 Posted July 14, 2010 muthu123, Try this, it is quick and dirty, but it works. (defun rem-spc (str / ) (setq str-list (vl-string->list str)) (setq new-list '("NIL")) (foreach x str-list (if (/= x 32) (setq new-list (append new-list (list x ))))) (setq new-list (cdr new-list)) (setq new-str-list (vl-list->string new-list)) ) Syntax: (setq str (rem-spc "This String Contains Spaces.")) Returns: "ThisStringContainsSpaces." The function will remove spaces in the string. Though you must note that there isn't any error checking in the function. But feel free to modify as needed. Regards, Hippe013 Quote
Lee Mac Posted July 14, 2010 Posted July 14, 2010 Hippe, Why the "NIL"? (defun nospace ( s ) (vl-list->string (vl-remove 32 (vl-string->list s))) ) Quote
Hippe013 Posted July 14, 2010 Posted July 14, 2010 Lee After the fact, I had noticed that this one was already solved. Yup, my bad. As for why the nil... Well... No Reason Now! I didn't quite understand the append. I thought it wasn't able to append to a nil symbol. So as a work around I would create a list with a dummy first member '("NULL"). At the end of the process I would then just remove the first item of the list. '("NULL" 0 1 2 3 4) -> '(0 1 2 3 4) But after some looking into it I find that: ... You can! (setq li nil) (setq cnt 0) (repeat 5 (setq li (append li (list cnt))) (setq cnt (1+ cnt)) li ) Thanks :wink: Quote
Lee Mac Posted July 14, 2010 Posted July 14, 2010 'cons' is the best and fastest solution when creating lists - only downside is that the list will be in reverse. 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.