linebreak

Ruby or regex to strip excess line breaks

How would you turn this: Dear Fred How are you? Regards John Into this: Dear Fred How are you? Regards John Note: Single and double breaks are allowed, but no more than that. For example, we want to go from: "Dear Fred\n\n\n\nHow are you?\n\n\n\n\n\n\nRegards\nJohn" to "Dear Fred\n\nHow are you?\n\nRegards\nJohn" But...

Width of a <td> is narrower when I use a <br> in it on a fixed width <table>. Why?

I have this HTML code fragment (in a valid document using strict doctype): <p>Without &lt;br /&gt;</p> <table border="1" width="220"> <tbody> <tr> <td>lorem</td> <td>ipsum</td> <td>lorem ipsum</td> <td>lorem</td> <td>ipsum</td> </tr> </tbody> </table> <p>With &lt;br /&gt;</p> <table borde...

Writing TXT File with PHP, Want to Add an Actual Line Break

I am writing a TXT file using PHP. I want to insert actual line breaks into the TXT file wherever necessary. I have tried all combinations of \n \r \r\n \n\r ... but these are not causing any linebreaks to appear - in most cases, I am seeing the text "\n" appear in the TXT file, with no linebreak. I have also tried chr(13). Any other i...

How to use NSLineSeparatorCharacter and NSParagraphSeparatorCharacter?

I wonder how I can use the constants NSLineSeparatorCharacter and NSParagraphSeparatorCharacter as a parameter to a function instead of hard coding \n. - (id)initWithSeparator:(id)separator { m_separator = separator; } What would be the correct parameter type and what conversion needs to be done? Depending on the file contents I wish...

Java code for wrapping text lines to a max line width

Before I re-invent the wheel (poorly), I'd like to know if there is a some existing Java code for wrapping text lines to a given maximum width. Ideally it would: respect existing linebreaks break up lines that exceed a maximum length on word boundaries break up words whose length exceeds the maximum line width by inserting hyphens Ed...