Questions tagged [line-breaks]

Whitespace that forces text layout to continue at the start of the next line.

The characters that define line breaks vary between computer system families. Windows systems typically use carriage return + line feed (CR + LF) (0x0D, 0x0A in ASCII) characters to indicate a line break in text. Unix based systems typically use LF (0x0A) alone to indicate a line break.

In programming languages \n, \r or \r\n is often used to create line breaks in a string e.g.:

variable = "Line 1\nLine2"

There's the Mandatory Break (NL, PS) and the Line Feed (LF) and the Next Line (NEL) which causes a line break after and then the Carriage Return (CR) which causes a line break after EXCEPT between CR and LF. Then there's the Combining Marks prohibiting a break between neighboring characters and similarly the Word Joiner and Non-breaking Space which prohibiting a line break to the left or the right. And lets not forget the Zero Width Space and good ol' fashion Space which are just dying to be broken by a line-break.

Breaks can occur wherever there's a break opportunity and break opportunities occur before or after dashes, spaces, hyphens, punctuation, and general characters.

In the US spaces and hyphens determine breaks. But that's not the case everywhere. In East Asia, for example, line breaks can occur ANYWHERE unless they're explicitly prohibited.

In Thailand they don't recognize space at all. Word breaks are defined by syllable boundaries rather than spaces. Thankfully Unicode has no algorithms to define such boundaries and thus, we can only assume.. what happens in Thailand stays in Thailand.



iint
findLineBrk(enum break_class *pcls, enum break_action *pbrk, int cch) {

    if (!cch) return 0;

    enum break_class cls = pcls[0]; // class of 'before' character

    // treat SP at start of input as if it followed a WJ
    if (cls == SP) cls = WJ;

    // loop over all pairs in the string up to a hard break
    for (int ich = 1; (ich 

page 38


2203 questions
1352
votes
10 answers

How can I do a line break (line continuation) in Python?

Given: e = 'a' + 'b' + 'c' + 'd' How do I write the above in two lines? e = 'a' + 'b' + 'c' + 'd'
Ray
  • 187,153
  • 97
  • 222
  • 204
1111
votes
10 answers

Difference between CR LF, LF and CR line break types

I'd like to know the difference (with examples if possible) between CR LF (Windows), LF (Unix) and CR (Macintosh) line break types.
eozzy
  • 66,048
  • 104
  • 272
  • 428
682
votes
7 answers

Is it possible to break a long line to multiple lines in Python?

Just like C, you can break a long line into multiple short lines. But in Python, if I do this, there will be an indent error... Is it possible?
Bin Chen
  • 61,507
  • 53
  • 142
  • 183
676
votes
11 answers

How to insert a line break in a SQL Server VARCHAR/NVARCHAR string

I didn't see any similar questions asked on this topic, and I had to research this for something I'm working on right now. Thought I would post the answer for it in case anyone else had the same question.
Mark Struzinski
  • 32,945
  • 35
  • 107
  • 137
647
votes
14 answers

How to read a file without newlines?

In Python, calling e.g. temp = open(filename,'r').readlines() results in a list in which each element is a line from the file. However, these strings have a newline character at the end, which I don't want. How can I get the data without the…
Yotam
  • 9,789
  • 13
  • 47
  • 68
572
votes
11 answers

Line break in HTML with '\n'

Is there a way to make HTML properly treat \n line breaks? Or do I have to replace them with
?
abc def ghi
stkvtflw
  • 12,092
  • 26
  • 78
  • 155
536
votes
19 answers

How to force a line break in a long word in a DIV?

Okay, this is really confusing me. I have some content inside of a div like so:
Thisisatest.Thisisatest.Thisisatest.Thisisatest.Thisisatest.Thisisatest.
However, the…
Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
523
votes
28 answers

How to line-break from css, without using
?

How to achieve same output without
?

hello
How are you

output: hello How are you
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852
521
votes
38 answers

Convert ^M (Windows) line breaks to normal line breaks

Vim shows ^M on every line ending. How do I replace this with a normal line break in a file opened in Vim?
ByteNirvana
  • 5,640
  • 4
  • 21
  • 20
480
votes
26 answers

Multiple lines of text in UILabel

Is there a way to have multiple lines of text in UILabel like in the UITextView or should I use the second one instead?
Ilya Suzdalnitski
  • 52,598
  • 51
  • 134
  • 168
425
votes
16 answers

How do I specify new lines in a string in order to write multiple lines to a file?

How can I indicate a newline in a string in Python, so that I can write multiple lines to a text file?
FabianCook
  • 20,269
  • 16
  • 67
  • 115
421
votes
7 answers

No line-break after a hyphen

I'm looking to prevent a line break after a hyphen - on a case-by-case basis that is compatible with all browsers. Example: I have this text: 3-3/8" which in HTML is this: 3-3/8” The problem is that near the end of a line, because of the…
Sparky
  • 98,165
  • 25
  • 199
  • 285
388
votes
7 answers

Render a string in HTML and preserve spaces and linebreaks

I have an MVC3 app that has a details page. As part of that I have a description (retrieved from a db) that has spaces and new lines. When it is rendered the new lines and spaces are ignored by the html. I would like to encode those spaces and new…
Dan dot net
  • 6,119
  • 5
  • 28
  • 25
358
votes
15 answers

How to add a new line in textarea element?

I want to add a newline in a textarea. I tried with \n and
tag but are not working. You can see above the HTML code. Can you help me to insert a newline in a textarea?