Word wrap: Difference between revisions

Content deleted Content added
m corrected a misspelling, added a category.
Alextretyak (talk | contribs)
Added 11l
Line 25: Line 25:
{{Template:Strings}}
{{Template:Strings}}
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Go}}

<lang 11l>F word_wrap(text, line_width)
V words = text.split_py()
I words.empty
R ‘’
V wrapped = words[0]
V space_left = line_width - wrapped.len
L(word) words[1..]
I word.len + 1 > space_left
wrapped ‘’= "\n"word
space_left = line_width - word.len
E
wrapped ‘’= ‘ ’word
space_left -= 1 + word.len
R wrapped

V frog = ‘
In olden times when wishing still helped one, there lived a king
whose daughters were all beautiful, but the youngest was so beautiful
that the sun itself, which has seen so much, was astonished whenever
it shone in her face. Close by the king's castle lay a great dark
forest, and under an old lime-tree in the forest was a well, and when
the day was very warm, the king's child went out into the forest and
sat down by the side of the cool fountain, and when she was bored she
took a golden ball, and threw it up on high and caught it, and this
ball was her favorite plaything.’

L(width) (72, 80)
print(‘Wrapped at ’width":\n"word_wrap(frog, width))
print()</lang>

{{out}}
<pre>
Wrapped at 72:
In olden times when wishing still helped one, there lived a king whose
daughters were all beautiful, but the youngest was so beautiful that the
sun itself, which has seen so much, was astonished whenever it shone in
her face. Close by the king's castle lay a great dark forest, and under
an old lime-tree in the forest was a well, and when the day was very
warm, the king's child went out into the forest and sat down by the side
of the cool fountain, and when she was bored she took a golden ball, and
threw it up on high and caught it, and this ball was her favorite
plaything.

Wrapped at 80:
In olden times when wishing still helped one, there lived a king whose daughters
were all beautiful, but the youngest was so beautiful that the sun itself, which
has seen so much, was astonished whenever it shone in her face. Close by the
king's castle lay a great dark forest, and under an old lime-tree in the forest
was a well, and when the day was very warm, the king's child went out into the
forest and sat down by the side of the cool fountain, and when she was bored she
took a golden ball, and threw it up on high and caught it, and this ball was her
favorite plaything.

</pre>


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==