could be many ways, and many answers, honestly; depending on what you mean by spaces. Below statement will count every single space. if you have 2 spaces between two words then it will be counted as 2 and not 1. No consideration given to new line characters or paragraphs
(length (vl-remove-if-not '(lambda (x) (= x 32)) (vl-string->list (cdr (assoc 1 (entget (car (entsel))))))))
it works
thank you
One last question.
How about counting the number of lines in mtext?
@Ranjit_Singh wrote:could be many ways, and many answers, honestly; depending on what you mean by spaces. Below statement will count every single space. if you have 2 spaces between two words then it will be counted as 2 and not 1. No consideration given to new line characters or paragraphs
(length (vl-remove-if-not '(lambda (x) (= x 32)) (vl-string->list (cdr (assoc 1 (entget (car (entsel))))))))
@Ranjit_Singh wrote:could be many ways, and many answers, honestly; depending on what you mean by spaces. Below statement will count every single space. if you have 2 spaces between two words then it will be counted as 2 and not 1. No consideration given to new line characters or paragraphs
(length (vl-remove-if-not '(lambda (x) (= x 32)) (vl-string->list (cdr (assoc 1 (entget (car (entsel))))))))
(+ 1 (length (vl-remove-if-not '(lambda (x) (= x 92)) (vl-string->list (cdr (assoc 1 (entget (car (entsel)))))))))
If mtext is numbered or formatted then above expression may need to factor that in
@marlance wrote:
it works
thank you
One last question.
How about counting the number of lines in mtext?
@Ranjit_Singh wrote:could be many ways, and many answers, honestly; depending on what you mean by spaces. Below statement will count every single space. if you have 2 spaces between two words then it will be counted as 2 and not 1. No consideration given to new line characters or paragraphs
(length (vl-remove-if-not '(lambda (x) (= x 80)) (vl-string->list (cdr (assoc 1 (entget (car (entsel))))))))I got it. I just change "32" to "80".
(ascii " ");returns 32
(ascii ""\P");returns 80
Caution:
I'm still running 2002 where "\P" marks a new line/paragraph. But someone recently pointed out that "\n" creates a new line these days as well.
You should check it out.
John F. Uhden