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

17
LINES

< > BotCompany Repo | #1006746 // fixNewLines - convert both sole \r and \r\n to \n

JavaX fragment (include)

1  
static S fixNewLines(S s) {
2  
  int i = indexOf(s, '\r');
3  
  if (i < 0) ret s;
4  
  int l = s.length();
5  
  StringBuilder out = new(l);
6  
  out.append(s, 0, i);
7  
  for (; i < l; i++) {
8  
    char c = s.charAt(i);
9  
    if (c != '\r')
10  
      out.append(c);
11  
    else {
12  
      out.append('\n');
13  
      if (i+1 < l && s.charAt(i+1) == '\n') ++i;
14  
    }
15  
  }
16  
  ret out.toString();
17  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006746
Snippet name: fixNewLines - convert both sole \r and \r\n to \n
Eternal ID of this version: #1006746/4
Text MD5: 5982ac1dede891004b234a6fd935da8e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-12 15:01:59
Source code size: 373 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 519 / 552
Version history: 3 change(s)
Referenced in: [show references]