Word wrap: Difference between revisions
Content added Content deleted
(Add source for Rust) |
(Word wrap en FreeBASIC) |
||
Line 1,755: | Line 1,755: | ||
</pre> |
</pre> |
||
For text flowing purposes the actual source lister expected to find block comments with a space after the C (so that column three was the first character of the text to be flowed), so the above source would be listed as-is - except for overprinting key words and underlining, easy with a lineprinter but much more difficult on modern printers that expect a markup language instead. |
For text flowing purposes the actual source lister expected to find block comments with a space after the C (so that column three was the first character of the text to be flowed), so the above source would be listed as-is - except for overprinting key words and underlining, easy with a lineprinter but much more difficult on modern printers that expect a markup language instead. |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>Dim Shared As String texto, dividido() |
|||
texto = "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." |
|||
Sub Split(splitArray() As String, subject As String, delimitador As String = " ") |
|||
Dim As Integer esteDelim, sgteDelim, toks |
|||
Dim As String tok |
|||
Redim splitArray(toks) |
|||
Do While Strptr(subject) |
|||
sgteDelim = Instr(esteDelim + 1, subject, delimitador) |
|||
splitArray(toks) = Mid(subject, esteDelim + 1, sgteDelim - esteDelim - 1) |
|||
If sgteDelim = FALSE Then Exit Do |
|||
toks += 1 |
|||
Redim Preserve splitArray(toks) |
|||
esteDelim = sgteDelim |
|||
Loop |
|||
End Sub |
|||
Sub WordWrap(s As String, n As Integer) |
|||
Split(dividido(),s," ") |
|||
Dim As String fila = "" |
|||
For i As Integer = 0 To Ubound(dividido) |
|||
If Len(fila) = 0 Then |
|||
fila = fila & dividido(i) |
|||
Elseif Len(fila & " " & dividido(i)) <= n Then |
|||
fila = fila & " " & dividido(i) |
|||
Else |
|||
Print fila |
|||
fila = dividido(i) |
|||
End If |
|||
Next i |
|||
If Len(fila) > 0 Then Print dividido(Ubound(dividido)) |
|||
End Sub |
|||
Print "Ajustado a 72:" |
|||
WordWrap(texto,72) |
|||
Print !"\nAjustado a 80:" |
|||
WordWrap(texto,80) |
|||
Sleep |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Ajustado a 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 |
|||
plaything. |
|||
Ajustado a 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 |
|||
plaything. |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |