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

17
LINES

< > BotCompany Repo | #1003503 // countFixer - fixes 1st, 2nd etc.

JavaX fragment (include)

static L<S> countFixer_them = splitAtSpace("nd st rd th");

static S countFixer(S s) {
  L<S> tok = nlTok2(s);
  for (int i = 1; i+2 < l(tok); i += 2)
    if (isInteger(tok.get(i)) && contains(countFixer_them, tok.get(i+2))) pcall {
      // Is it correct?
      long l = parseLong(tok.get(i));
      long d = l % 10, h = l % 100;
      tok.set(i+2, h-d == 10 ? "th"
        : d == 1 ? "st"
        : d == 2 ? "nd"
        : d == 3 ? "rd"
        : "th");
    }
  ret join(tok);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003503
Snippet name: countFixer - fixes 1st, 2nd etc.
Eternal ID of this version: #1003503/1
Text MD5: aec9d577b0e540bb51d8921ed2378e96
Author: stefan
Category: javax / talking robots
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-10 00:33:18
Source code size: 496 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 579 / 584
Referenced in: [show references]