Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1033233 // regularLineBreaks

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3796L/22K).

sS regularLineBreaks(int charsPerLine, S s) {
  if (l(s) < charsPerLine) ret s;
  
  new StringBuilder buf;
  int n = l(s), j = 0;

  for i to n: {
    buf.append(s.charAt(i));
    if (++j >= charsPerLine) {
      buf.append('\n');
      j = 0;
    }
  }
  
  ret str(buf);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033233
Snippet name: regularLineBreaks
Eternal ID of this version: #1033233/2
Text MD5: 1a5593e53b3511ddbe4d797927ad7955
Transpilation MD5: 1f8a3913b84bf088a68ad197601136b0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-16 07:48:58
Source code size: 290 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 87 / 117
Version history: 1 change(s)
Referenced in: [show references]