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

15
LINES

< > BotCompany Repo | #1022519 // replaceLine_keepingPadding

JavaX fragment (include)

// a must be trimmed
sS replaceLine_keepingPadding(S text, S a, S b) {
  LS lines = lines(text);
  bool change = false;
  for i over lines: {
    S s = lines.get(i);
    S trimmed = trim(s);
    if (eqic(trimmed, a)) {
      int idx = indexOf(s, trimmed);
      lines.set(i, replaceSubstring(s, idx, idx+l(trimmed), b));
      set change;
    }
  }
  ret change ? lines_possiblyRTrim(text, lines) : text;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022519
Snippet name: replaceLine_keepingPadding
Eternal ID of this version: #1022519/2
Text MD5: 1ae94edbeacf8c90ba02298e745f2212
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-20 00:01:21
Source code size: 420 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 276 / 280
Version history: 1 change(s)
Referenced in: [show references]