我使用下面的代码将句子分成许多部分,但我在这里看到了一些问题,一个单词进入了第二行,第二行的前端看起来更模糊。我们能避免这种情况吗?
library(shiny)
HTML(paste0(gsub("(.{10})", "\1n", "I saw a beautiful moon tonight")))
I saw a be
autiful mo
on tonight
预期输出(这应该是动态的。因此代码应该自行识别有意义的单词(
I saw a
beautiful
moon tonight
您可以使用内置的R函数strwrap
:
strwrap("I saw a beautiful moon tonight", width=10)
# [1] "I saw a" "beautiful" "moon" "tonight"