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
[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…