How to strip values as text at a text list

How to strip values as text at a text list

devitg
Advisor Advisor
845 Views
13 Replies
Message 1 of 14

How to strip values as text at a text list

devitg
Advisor
Advisor

Please , I need to strip and discard  all text that only represent a value , and keep text despite it have some value in. 

From this list 

 

(setq text+value-list(list "SUBRASANTE"
   "C.T.N."	"SUB-BASE"   "0.00"	  "CORTE CAJA 2"
   "CAJA 100%"	"0.01"	     "0.02"	  "0.03"       "16.59"
   "17.86"	"18.41"	     "2025.81"	  "31421.14"   "22.04"
   "22.39"	"33.62"
  ))

To this one 

 

(setq no-value-list
       (list
	 "SUBRASANTE" "C.T.N." "SUB-BASE" "CORTE CAJA 2" "CAJA 100%") ;_ end of list
) ;_ end of setq

 

 

0 Likes
846 Views
13 Replies
Replies (13)
Message 2 of 14

paullimapa
Mentor
Mentor
(foreach itm text+value-list(if(not(numberp(read itm)))(setq no-value-list(append no-value-list(list itm)))))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 14

komondormrex
Mentor
Mentor

check the following

 

(setq no-value-list
	 (vl-remove-if '(lambda (text) (vl-every '(lambda (_ascii) (member _ascii '(45 46 48 49 50 51 52 53 54 55 56 57))) 
	 										  (vl-string->list text)
								   )
					)
					text+value-list
	 )
)

 

0 Likes
Message 4 of 14

hak_vz
Advisor
Advisor
(setq non-numeric(vl-remove-if '(lambda (item)(numberp (read item))) text+value-list))
>> ("SUBRASANTE" "C.T.N." "SUB-BASE" "CORTE CAJA 2" "CAJA 100%")

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 14

komondormrex
Mentor
Mentor

(read) that is what @paullimapa has proposed. will not work with "123 aaa" strings btw.

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@komondormrex wrote:
.... (member _ascii '(46 48 49 50 51 52 53 54 55 56 57))) ....

I think that should include 45 for "-".  Without that, a purely numerical but negative value will be kept in the list.  And for those who use a comma for a decimal separator, use 44 instead of 46.

Kent Cooper, AIA
Message 7 of 14

hak_vz
Advisor
Advisor

@komondormrex wrote:

(read) that is what @paullimapa has proposed. will not work with "123 aaa" strings btw.


For me it works ok. This is not numeric string and as a such is not included in result. OP don't have such string in his example.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 8 of 14

ronjonp
Advisor
Advisor

And for the WIN.

0 Likes
Message 9 of 14

pbejse
Mentor
Mentor

@ronjonp wrote:

And for the WIN.


There you go 👍

 

Maybe another one.

(vl-remove-if '(lambda (s) (wcmatch s "#*")) text+value-list)

 

0 Likes
Message 10 of 14

john.uhden
Mentor
Mentor

@ronjonp & @pbejse ,

Not so fast you guys.

By design, your wildcard spec will pick up "100%."
"#*" does not remove "33RPM" or "22 mpg" or "1600 Pennsylvania Avenue."

And what about negative numbers?

Test this out:

(defun isnumstr (str / lst numbers)
  (setq lst (vl-string->list str))
  (setq numbers '(46 48 49 50 51 52 53 54 55 56 57))
  (and
    (or (vl-position (car lst) '(45 46))
        (vl-position (car lst) numbers)
    )
    (vl-every '(lambda (x)(vl-position x numbers)) (cdr lst))
  )
)
;; Returns either T or nil

Sadly, it won't reject "123..45" but who numbers like that anyway?

And if a "+" character counts as a number then just add 43 to '(45 46).

 

John F. Uhden

0 Likes
Message 11 of 14

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

.... it won't reject "123..45" but who numbers like that anyway?

And if a "+" character counts as a number....


But the (distof) approach in the "for the WIN" link will.  And it will accept "+123.45" as numerical.

Kent Cooper, AIA
0 Likes
Message 12 of 14

john.uhden
Mentor
Mentor

@Kent1Cooper ,

YOU ARE RIGHT (as usual)...

(defun c:test1 ()
  (vl-remove-if '(lambda (x)(numberp (distof x))) text-list)
)
(defun c:test2 ()
  (vl-remove-if '(lambda (x)(numberp (read x))) text-list)
)
(defun c:test3 ()
  (vl-remove-if '(lambda (x)(isnumstr x)) text-list)
)
Command: (setq text-list '("C.T.N " "SUBBASE" "22 MPG" "23.01" "CORTE CAJA 2" "34.52" "33 RPM" "1600 PENN. AVE." "57.0"))
("C.T.N " "SUBBASE" "22 MPG" "23.01" "CORTE CAJA 2" "34.52" "33 RPM" "1600 
PENN. AVE." "57.0")

Command: TEST1
("C.T.N " "SUBBASE" "22 MPG" "CORTE CAJA 2" "33 RPM" "1600 PENN. AVE.")

Command:
Command: TEST2
("C.T.N " "SUBBASE" "CORTE CAJA 2")

Command:
Command: TEST3
("C.T.N " "SUBBASE" "22 MPG" "CORTE CAJA 2" "33 RPM" "1600 PENN. AVE.")

It's not that I was wrong.  I knew that "#*" wouldn't work,  but I hadn't tried distof.

What an easy solution and THE WINNER!

BTW, it finally came to me that "distof" is not short for "distance of" but for "distance to float."

Just like "atof" and "angtof."

   (Also BTW, I found it impossible to underscore only the f in float.)

John F. Uhden

0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

....   (... I found it impossible to underscore only the f in float.)


[For future reference, if you find it hard to select the particular character(s) you want, for underlining or boldfacing or italicizing or changing color or whatever:  Use the left/right arrow buttons to position your cursor beside a character or at one end of a range of multiple characters.  Hold down SHIFT while you use the left/right arrow buttons to sweep across what you want to select.]

Kent Cooper, AIA
0 Likes
Message 14 of 14

john.uhden
Mentor
Mentor

Thank you, @Kent1Cooper , but as I said, impossible.  It's most likely due to this editor, or there is super strong magnetism between fs and ls.

I'll try it again... float, flower, cauliflower, baffle, rifle.  Oh, well.

first  ... seems to be just the f's fault, though from, afford, and famous behave properly.

Doesn't happen in Word.

It seems it has to do with the proximity of "f" to the following letter, or maybe the verticality of the following letter.  fun  I dunno; maybe use a different font?

float, yep.

John F. Uhden

0 Likes