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

18
LINES

< > TinyBrain | #1002637 - substring - exception-free (safe) version of String.substring

JavaX fragment (include)

static S substring(S s, int x) {
  ret substring(s, x, l(s));
}

static S substring(S s, int x, int y) {
  if (s == null) return null;
  if (x < 0) x = 0;
  if (x >= s.length()) return "";
  if (y < x) y = x;
  if (y > s.length()) y = s.length();
  return s.substring(x, y);
}

ifclass IntRange
static S substring(S s, IntRange r) {
  ret r == null ? null : substring(s, r.start, r.end);
}
endif

Author comment

Began life as a copy of #1001853

download  show line numbers  debug dex   

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

No comments. add comment

Snippet ID: #1002637
Snippet name: substring - exception-free (safe) version of String.substring
Eternal ID of this version: #1002637/8
Text MD5: c68c7c010c3d88679a2134993bc7977f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-11 13:08:08
Source code size: 412 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 278 / 934
Version history: 7 change(s)
Referenced in: [show]