This is the task:
write a function that prints out a boxed sentence as follows:
s<-"This is a sentence with different word lengths"
box(s) prints the following"
XXXXXXXXXXXXX
X this X
X is X
X a X
X sentence X
X with X
X different X
X word X
X lengths X
XXXXXXXXXXXXX
The trick is that every word should be centered inside the box of X's The length of the top and bottom string of X's should therefore be 4 plus length of longest word All X's on the right should line up. There should be no quotes.
To start, I wrote this line:
s<-cat("This","is","a","sentence","with","different","word","lengths",sep=" ",fill=2)
which wraps the text so that there is one word on each line. I am not sure how to get the X's to form a box around the wrapped string. I think I am supposed to use nchar(s), but I am not sure how it is useful. Any help would be appreciated!