Skip to main content
Inspiring
Mar 30, 2017 2:21 PM UTC
Answered

Counting line in paragraph

Hello,

I usually work with structured FM doc, but for once i need to work with unstructured doc.

I need to make a script that check if there is only few chararter at the last line of a paragraph, and if yes, to apply a "spread -2%". and check if i lost one line.

I was thinking, if i can compare the number of line of a paragraph before and after the "spread -2%" and if it's "after" is smaller than "before".

If yes => i lost one line in my paragraph.

In million paragaph, i can win few pages in my doc (doc large than 1.000 pages)

I already have script to walkthrouth all the paragraph of a doc, another to apply and/or check paragraph values (spread).

But how can i count the number of line in one paragraph?

Do i have to put my cursor in each line of my paragraph and check the FTI_LineEnd (normal, hard, hyphen) to know when i reach the end of my paragraph? Or there is another way?

This topic is closed to new replies. Start a new post to keep the conversation going.
Russ WardCorrect answer
Legend
Mar 31, 2017 12:47 PM UTC

After posting that, I thought of this, which seems to do the same thing:

var ti = pgf.GetText(Constants.FTI_LineEnd);

If it requires less memory and/or processing, that might be better. I don't know if it does or not.

Russ

8 replies

Legend
Mar 31, 2017 12:45 PM UTC

Hi philippep2776167,

I think the easiest way to count lines in a paragraph is to retrieve the text items, then just look at the length of the array. For example:

var ti = pgf.GetText(Constants.FTI_String);

The length of "ti" will be the number of lines in the paragraph. For example, if the paragraph is 5 lines long, then:

ti.len == 5

Russ

Translate
Russ WardCorrect answer
Legend
Mar 31, 2017 12:47 PM UTC

After posting that, I thought of this, which seems to do the same thing:

var ti = pgf.GetText(Constants.FTI_LineEnd);

If it requires less memory and/or processing, that might be better. I don't know if it does or not.

Russ

Translate
4everJang
Legend
Mar 31, 2017 12:51 PM UTC

Hi Russ (and Philippe)

The array of strings may in fact have more elements than the number of lines. I cannot give you precise examples for unstructured text, but I did see them. The search for LineEnd is safer.

Ciao

Jang

Translate