Libraryless. Click here for Pure Java version (56L/1K).
1 | sS shortenInTheMiddle(int max, CharSequence s) { |
2 | if (s == null) ret ""; |
3 | if (max < 0) ret str(s); |
4 | if (s.length() <= max) ret str(s); |
5 | S shortener = "..."; |
6 | int m = max-shortener.length(); |
7 | ret subCharSequence(s, 0, m-m/2) |
8 | + shortener |
9 | + subCharSequence(s, s.length()-m/2); |
10 | } |
Began life as a copy of #1000644
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: | #1029287 |
Snippet name: | shortenInTheMiddle |
Eternal ID of this version: | #1029287/5 |
Text MD5: | b3dc196ab8563286d5f82dc22753896d |
Transpilation MD5: | 7b7cbad7393df23df75ec42d7b2b37ac |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-29 22:52:37 |
Source code size: | 298 bytes / 10 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 213 / 305 |
Version history: | 4 change(s) |
Referenced in: | [show references] |