count the number of space in mtext

count the number of space in mtext

marlance
Advocate Advocate
1,092 Views
5 Replies
Message 1 of 6

count the number of space in mtext

marlance
Advocate
Advocate

Hello

 

 

How to count the number of space in mtext?

 

 

 

 

0 Likes
Accepted solutions (1)
1,093 Views
5 Replies
Replies (5)
Message 2 of 6

Ranjit_Singh
Advisor
Advisor

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))))))))
0 Likes
Message 3 of 6

marlance
Advocate
Advocate

 

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))))))))

 

0 Likes
Message 4 of 6

Ranjit_Singh
Advisor
Advisor
Accepted solution
(+ 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 

0 Likes
Message 5 of 6

marlance
Advocate
Advocate

@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

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 6 of 6

john.uhden
Mentor
Mentor

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

0 Likes