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)

static S fixNewLines(S s) {
  int i = indexOf(s, '\r');
  if (i < 0) ret s;
  int l = s.length();
  StringBuilder out = new(l);
  out.append(s, 0, i);
  for (; i < l; i++) {
    char c = s.charAt(i);
    if (c != '\r')
      out.append(c);
    else {
      out.append('\n');
      if (i+1 < l && s.charAt(i+1) == '\n') ++i;
    }
  }
  ret out.toString();
}

download  show line numbers  debug dex   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

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: 342 / 352
Version history: 3 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1006746 & http://1006746.tinybrain.de