Extra space in printing

Hi,

I have users enter text into a textarea box and then it gets printed on the report.

My problem is some paragraphs have one line of space after and some have two.
Don’t know why.

Is there a way to detect that and skip extra paragraph or end of line characters?

And also would that code be different on Mac vs. Windows?

-Tim

are the one vs two, due to the incoming text?
or do you think your app is “adding” them?

Um… Trim?

ReplaceAll (yourText, (EndOfLine + EndOfLine), EndOfLine)

I am doing a split on EndOfLine trying to detect paragraphs and then just add one EndOfLine between them but it’s not working.

Going to try this and see if it fixes it!

I do have that and it is not making any difference. Weird.

Egads
I added the replaceall code to replace double EndOfLines with single EndOflines…
in 2 places just to be double sure…

STILL doesn’t work:

https://www.screencast.com/t/bNTsOrKs2

(also have Trim for good measure)
Argh!

-Tim

Can you make an example out of your code or post some of your code here?

It may be that there’s some extra whitespace between the EndOfLines that prevents the ReplaceAll from working. You could try this:

Function CompressEndOfLine(s1 As String) as String 'Removes duplicate EndOfLine characters from text. 'Also trims leading and trailing whitespace. dim s As String =s1 'Convert all tabs into spaces s=ReplaceAll(s,chr(9)," ") dim L As Integer = len(s)+1 'Replace duplicate line endings (with included spaces) repeatedly until length stops changing While len(s)<>L L=len(s) s=ReplaceAll(s,EndOfLine+" ",EndOfLine) s=ReplaceAll(s," "+EndOfLine,EndOfLine) s=ReplaceAll(s,EndOfLine+EndOfLine,EndOfLine) wend return trim(s) End Function

To expand on Weaver’s code using RegEx. Possibly more robust. Deals with other whitespace such as TAB. Try to deal with the various line endings that might be in the original text possibly pasted from some weird source.

As a side issue Tim, what does the problematic text look like in a text editor such as BBEdit where you can optionally “see” the “invisible” characters?

I suspect that you do not have to enclose all this in the

[code]While Len(curedString) <> L

Wend[/code]

but you could test this. Anyway, below is the suggested code.

[code]Public Function CompressEndOfLine(s1 As String) as String
Dim curedString As String = s1

curedString = ReplaceAll(curedString, EndOfLine.Windows, EndOfLine)
curedString = ReplaceAll(curedString, EndOfLine.Macintosh, EndOfLine)
curedString = ReplaceAll(curedString, EndOfLine.Unix, EndOfLine)

Dim re As New RegEx
Dim match As RegExMatch

re.ReplacementPattern = EndOfLine
re.Options.ReplaceAllMatches = True

re.SearchPattern = EndOfLine + “\s*” + EndOfLine
match = re.Search(curedString)
If match <> Nil Then
curedString = re.Replace(curedString, 0)
End If

Return Trim(curedString)
End Function[/code]

The code above could probably be a little simpler

[code]Public Function CompressEndOfLine(s1 As String) as String
Dim curedString As String = s1

curedString = ReplaceAll(curedString, EndOfLine.Windows, EndOfLine)
curedString = ReplaceAll(curedString, EndOfLine.Macintosh, EndOfLine)
curedString = ReplaceAll(curedString, EndOfLine.Unix, EndOfLine)

Dim re As New RegEx

re.ReplacementPattern = EndOfLine
re.Options.ReplaceAllMatches = True
re.SearchPattern = EndOfLine + “\s*” + EndOfLine

curedString = re.Replace(curedString)

Return Trim(curedString)

End Function[/code]

Yes. I’d intended to mention that Regex would be a more efficient way to do this, but I’m not a Regex expert. :frowning:

First off, send your output through:

system.debuglog(EncodeURLComponent(OutputString))

So you can see what is actually causing the breaks, then you can use the above suggestions to remove it :slight_smile:

OK Julian I did that.
The only thing between paragraphs is: %0D%0A

[quote=371946:@Robert Livingston]The code could probably be a little simpler

curedString = ReplaceAll(curedString, EndOfLine.Windows, EndOfLine) curedString = ReplaceAll(curedString, EndOfLine.Macintosh, EndOfLine) curedString = ReplaceAll(curedString, EndOfLine.Unix, EndOfLine)[/quote]
Or even simpler by using ReplaceLineEndings

[quote=371992:@Tim Turner]OK Julian I did that.
The only thing between paragraphs is: %0D%0A[/quote]
I guess if you have single %0D%0A between paragraphs, then your OutputString is Ok.

The only thing I can see from your screencast is that the last line of the paragraph with single space is shorter (only has 5 words that line), while the others that have extra space are longer (at least 7 words). I haven’t learn about printing and formatting so I can’t help with that.

I think I have narrowed it down to using BKeeney Shorts.

This line drops the cursor down after placing a paragraph based on the calculated height of that paragraph.

iTop = iTop + oText.Bounds.Height

But logging the Bounds.Height is giving weird valus vs. the number of lines in each paragraph.
For example 2 paragraphs have 6 lines but the oText.Bounds.Height for each is different.

So I now don’t think it is related to EndOfLine or extra characters…