(defun check_del (str_line /)
(cond
((eq 44 (last (vl-string->list str_line ))) ",")
((eq 58 (last (vl-string->list str_line ))) ":")
((eq 59 (last (vl-string->list str_line ))) ";")
((eq 9 (last (vl-string->list str_line ))) "\t")
((eq 0 (last (vl-string->list str_line )))
(substr (vl-string-trim "0123456789" str_line) 1 1));it's working good, if the first item is numeric only
(T (alert "Impossible to read your text\nAsk your dork programmer about.")(exit)))
)(defun _GetDelim (s) (substr s (strlen s) 1))
(defun _RemEndDelim (lst / d)
(if (setq d (_GetDelim (car lst)))
(mapcar
(function
(lambda (x)
(vl-string-right-trim d x)
)
)
lst
)
)
)
_$ (_RemEndDelim (list "ST1,1022.519,927.347,100.522," "KON1,1022.519,927.347,100.522," "2,1022.519,927.347,100.522,"))
("ST1,1022.519,927.347,100.522" "KON1,1022.519,927.347,100.522" "2,1022.519,927.347,100.522")
_$
Code: [Select](defun _GetDelim (s) (substr s (strlen s) 1))
(defun _RemEndDelim (lst / d)
(if (setq d (_GetDelim (car lst)))
(mapcar
(function
(lambda (x)
(vl-string-right-trim d x)
)
)
lst
)
)
)
Example:Code: [Select]_$ (_RemEndDelim (list "ST1,1022.519,927.347,100.522," "KON1,1022.519,927.347,100.522," "2,1022.519,927.347,100.522,"))
("ST1,1022.519,927.347,100.522" "KON1,1022.519,927.347,100.522" "2,1022.519,927.347,100.522")
_$
you just need to remove the last not numeric character or you must also know the separator?Hi Marco, glad to see you :)
Code: [Select](defun _GetDelim (s) (substr s (strlen s) 1))
(defun _RemEndDelim (lst / d)
(if (setq d (_GetDelim (car lst)))
(mapcar
(function
(lambda (x)
(vl-string-right-trim d x)
)
)
lst
)
)
)
Example:Code: [Select]_$ (_RemEndDelim (list "ST1,1022.519,927.347,100.522," "KON1,1022.519,927.347,100.522," "2,1022.519,927.347,100.522,"))
("ST1,1022.519,927.347,100.522" "KON1,1022.519,927.347,100.522" "2,1022.519,927.347,100.522")
_$
Thanks so much, your function _RemEndDelim working good
on my files, but function _GetDelim is not good for me,
some time it return number instead of delimiter,
anyway thanks, friend, most part of work I'll be finish
(defun _RemEndDelim (lst)
(mapcar
(function
(lambda (x)
(vl-string-right-trim
","
(vl-string-right-trim ";" x)
)
)
)
lst
)
)
Thanks again it's working good :)
Hve just one issue with _GetDelim, eg:
(_GetDelim "KON1\t1022.519\t927.347\t100.522");<-- return 2
(_GetDelim "KON1\t1022.519\t927.347\t100.522\t");<-- return \t , good one
(defun _GetDelim (str_line / dels)
(setq dels (list 9 44 58 59))
(car
(vl-remove-if-not
'(lambda (x)
(member x dels)
) ;_ end of lambda
(vl-string->list str_line)
) ;_ end of vl-remove-if-not
) ;_ end of car
) ;_ end of defun
Hi Marco, glad to see you :)here I am after dinner (my wife is severe)...
...
The problem was resolved, thanks to all, guys :)
...
Try this one perhaps:Thanks Irne`Code - Auto/Visual Lisp: [Select]
The question is how to retrive a separator and to remove
ending separator in every line ( if this exists )
at runtime, in one shot only
@BlackBox: Why the foreach? You could accomplish the same thing thus:Code - Auto/Visual Lisp: [Select]
Anyhow fixo, why would you need to "know" what the delimiter is? Usually with these delimited strings you simply want to split them into usable items.The reason is on some files were badly formatted, I almost finish my work on today,