regex - Automatically inserting line breaks in long string -


is possible insert line breaks character string automatically adjust don't split words?

 nif <- as.character(c("i string", "so i",       "i string way long")) 

i found code in post splits words , add line break after each string avoid

  gsub('(.{1,20})', '\\1\n',nif) 

the output going this:

 "i string"    "so i"     "i string \n way long"  

you can use strwrap.

strwrap(nif, 20) # [1] "i string"      "so i"            "i string" # [4] "but way long"    sapply( strwrap(nif, 20, simplify=false), paste, collapse="\n" ) # [1] "i string"                       "so i"                             # [3] "i string\nbut way long" 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -