Libraryless. Click here for Pure Java version (2540L/16K).
static int shorten_default = 100; sS shorten(CharSequence s) { ret shorten(s, shorten_default); } sS shorten(CharSequence s, int max) { ret shorten(s, max, "..."); } sS shorten(CharSequence s, int max, S shortener) { if (s == null) ret ""; if (max < 0) ret str(s); return s.length() <= max ? str(s) : subCharSequence(s, 0, min(s.length(), max-l(shortener))) + shortener; } sS shorten(int max, CharSequence s) { ret shorten(s, max); }
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1000644 |
Snippet name: | shorten function |
Eternal ID of this version: | #1000644/9 |
Text MD5: | 05874cd24b584b697eeadfc8814cfca6 |
Transpilation MD5: | f82e05803c4a06693700102b6a704571 |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-25 12:47:08 |
Source code size: | 459 bytes / 15 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 839 / 9692 |
Version history: | 8 change(s) |
Referenced in: | #1002427 - Accellerating 629 (SPIKE) #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1012681 - shortenSymbol #1029287 - shortenInTheMiddle #1030134 - shorten_nullOnNull #1037261 - shortenToFirstAndLast #3000382 - Answer for ferdie (>> t = 1, f = 0) |