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

14
LINES

< > BotCompany Repo | #1026538 // replace_multi

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

Libraryless. Click here for Pure Java version (2203L/14K).

sS replace_multi(S s, Cl<S> a, S b) {
  if (s == null || empty(a) || b == null) ret s;
  for (S aa : a)
    s = s.replace(aa, b);
  ret s;
}

// replacements = in, out, in, out, ...
sS replace_multi(S s, S... replacements) {
  if (empty(s) || empty(replacements)) ret s;
  for (int i = 0; i+1 < l(replacements); i += 2)
    s = s.replace(replacements[i], replacements[i+1]);
  ret s;
}

Author comment

Began life as a copy of #1007775

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1026538
Snippet name: replace_multi
Eternal ID of this version: #1026538/2
Text MD5: e78eefc8c7b22e535addc542dda47fb8
Transpilation MD5: a752cd8f536933ee046f8d7990c956a6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-11 18:42:18
Source code size: 398 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 182 / 272
Version history: 1 change(s)
Referenced in: [show references]