37 lines
801 B
Text
37 lines
801 B
Text
t$ = "In olden times when wishing still helped one, there lived a king "
|
|
t$ = t$ + "whose daughters were all beautiful, but the youngest was so beautiful "
|
|
t$ = t$ + "that the sun itself, which has seen so much, was astonished whenever "
|
|
t$ = t$ + "it shone in her face.\n\n"
|
|
t$ = t$ + t$
|
|
|
|
t$ = trim$(t$)
|
|
|
|
input "Width: " width // user specifies width
|
|
|
|
dim p$(1)
|
|
|
|
d$ = " .,\n"
|
|
|
|
n = words(t$, p$(), d$)
|
|
|
|
for i = 1 to n
|
|
if p$(i) = "\n" or len(docOut$) + len(p$(i)) > width then
|
|
print docOut$
|
|
docOut$ = ""
|
|
end if
|
|
if p$(i) <> "\n" docOut$ = docOut$ + p$(i)
|
|
next i
|
|
print docOut$
|
|
|
|
sub words(w$, p$(), d$)
|
|
local n, i, p
|
|
|
|
n = split(w$, p$(), d$)
|
|
p = 1
|
|
|
|
for i = 1 to n
|
|
p$(i) = p$(i) + mid$(w$, p + len(p$(i)), 1)
|
|
p = p + len(p$(i))
|
|
next i
|
|
return n
|
|
end sub
|