Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,27 @@
string="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.";
wordWrap[textWidth_,spaceWidth_,string_]:=Module[{start,spaceLeft,masterString},
spaceLeft=textWidth;
start=1;
masterString={};
Do[
If[i+1>Length@StringSplit@string
,
p=StringSplit[string][[start;;i]];
AppendTo[masterString,{StringJoin@@Riffle[p,StringJoin@ConstantArray[" ",spaceWidth]]}]
,
If[StringLength[StringSplit@string][[i+1]]+spaceWidth>spaceLeft
,
spaceLeft=textWidth-StringLength[StringSplit@string][[i]];
start=i;
AppendTo[masterString,{StringJoin@@Riffle[p,StringJoin@ConstantArray[" ",spaceWidth]]}]
,
spaceLeft-=StringLength[StringSplit@string][[i]];
spaceLeft-=spaceWidth;
p=StringSplit[string][[start;;i]]
]
]
,
{i,1,Length@StringSplit@string}
];
StringJoin@@Riffle[masterString,"\n"]
];

View file

@ -0,0 +1,2 @@
wordWrap[72, 1, string]
wordWrap[80, 1, string]