Skip to main content
added 115 characters in body
Source Link
Prince John Wesley
  • 63.8k
  • 12
  • 90
  • 95

To keep white-space,Try this:

s = s.replaceAll("(.{0,"+ x+"})\\b", "$1\n"); 

To ignore white-space(trim)or the trimmed version,

s = s.replaceAll("(?:\\s*)(.{01,"+ x +"})(?:\\s+|\\s*$)", "$1\n"); 

To keep white-space,

s = s.replaceAll("(.{0,"+ x+"})\\b", "$1\n"); 

To ignore white-space(trim),

s = s.replaceAll("(.{0,"+ x +"})(?:\\s+|\\s*$)", "$1\n"); 

Try this:

s = s.replaceAll("(.{0,"+ x+"})\\b", "$1\n"); 

or the trimmed version,

s = s.replaceAll("(?:\\s*)(.{1,"+ x +"})(?:\\s+|\\s*$)", "$1\n") 
added 115 characters in body
Source Link
Prince John Wesley
  • 63.8k
  • 12
  • 90
  • 95

Try this:To keep white-space,

s = s.replaceAll("(.{0,"+ x+"})\\b", "$1\n"); 

To ignore white-space(trim),

s = s.replaceAll("(.{0,"+ x +"})(?:\\s+|\\s*$)", "$1\n"); 

Try this:

s = s.replaceAll("(.{0,"+ x+"})\\b", "$1\n"); 

To keep white-space,

s = s.replaceAll("(.{0,"+ x+"})\\b", "$1\n"); 

To ignore white-space(trim),

s = s.replaceAll("(.{0,"+ x +"})(?:\\s+|\\s*$)", "$1\n"); 
Source Link
Prince John Wesley
  • 63.8k
  • 12
  • 90
  • 95

Try this:

s = s.replaceAll("(.{0,"+ x+"})\\b", "$1\n");