1 | static S extractLastNLinesOfString(int n, S s) { |
2 | int i = l(s)-1; |
3 | // skip trailing new line |
4 | if (i >= 0 && s.charAt(i) == '\n') --i; |
5 | if (i >= 0 && s.charAt(i) == '\r') --i; |
6 | |
7 | while (n > 0 && i >= 0) { |
8 | if (s.charAt(i) == '\n') |
9 | if (--n == 0) break; |
10 | --i; |
11 | } |
12 | |
13 | ret substring(s, i+1); |
14 | } |
15 | |
16 | static S extractLastNLinesOfString(S s, int n) { |
17 | ret extractLastNLinesOfString(n, s); |
18 | } |
Began life as a copy of #1004746
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1018865 |
Snippet name: | extractLastNLinesOfString |
Eternal ID of this version: | #1018865/5 |
Text MD5: | 40e3c29d35264ec8d81510581cb57273 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-10-14 18:06:21 |
Source code size: | 416 bytes / 18 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 361 / 421 |
Version history: | 4 change(s) |
Referenced in: | [show references] |