Insert line breaks in long string — word wrap

前端 未结 4 1635
情书的邮戳
情书的邮戳 2020-12-03 01:15

Here is a function I wrote to break a long string into lines not longer than a given length

strBreakInLines <- function(s, breakAt=90, prepend=\"\") {
  w         


        
4条回答
  •  清歌不尽
    2020-12-03 01:40

    For further completeness, there's:

    • stringi::stri_wrap
    • stringr::str_wrap (which just ultimately calls stringi::stri_wrap

    The stringi version will deal with character sets better (it's built on the ICU library) and it's in C/C++ so it'll ultimately be faster than base::strwrap. It's also vectorized over the str parameter.

提交回复
热议问题