Wordwrap

Application Kata „Wordwrap“

Write an application that rearranges a text so that lines are wrapped at a given column width.

The following illustration shows how the application may look like.

1

The user will enter the text into a textbox. Furthermore the user gives the number of characters per line. The example shows 25 characters as the new line length. Clicking the Wrap button wraps the text. The result is shown in the lower textbox.

Variation #1

The program can be written as a command line application. Filename and width oft he wrapped text are given as command line parameters:

C:> wrap hansel-and-gretel.txt 25
Hansel and Gretel are
young children whose
father is a woodcutter.
When a great famine
settles over the land,
the woodcutter's abusive
second wife decides to
take the children into
the woods...

Variation #2

Integrate a hyphenation library like NHunspell [1] to split words into syllables.

Resources

[1] http://nhunspell.sourceforge.net/