Advertisement
EyesOfAHawk

Ordinal Suffix

Jun 5th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. //===== Hercules Script ======================================
  2. //= Ordinal Suffix
  3. //===== By ===================================================
  4. //= Wolfie of BlackoutRO (https://blackout-ro.net)
  5. //===== Forum Thread =========================================
  6. //= http://herc.ws/board/topic/14855-function-ordinal-suffix/
  7. //===== Description ==========================================
  8. //= In a string, returns the 'Ordinal Suffix' of a number,
  9. //  e.g. 1 -> 1st, 2 -> 2nd, 3 -> 3rd, etc.
  10. //===== Version ==============================================
  11. //= 1.1 - Implement sprintf() function (May 15, 2018)
  12. //      - Change repeating function to .@val1 & .@val2
  13. //= 1.0 - Initial Version (June 5, 2017)
  14. //===== Comments =============================================
  15. //= Do not claim this work as your own. Other than that, have
  16. //  fun. Use the 'callfunc()' script command to call this.
  17. //= E.g. mesf("%s", callfunc("Ordinal_Suffix", 5));
  18. //  Will return a mes box saying "5th".
  19. //============================================================
  20.  
  21. function    script  Ordinal_Suffix  {
  22.     .@str$ = sprintf("%d", getarg(0));
  23.     .@val1 = atoi(charat(.@str$, getstrlen(.@str$) - 2));
  24.     .@val2 = atoi(charat(.@str$, getstrlen(.@str$) - 1));
  25.  
  26.     // Special case for 11th, 12th and 13th
  27.     if (.@val1 == 1 && (.@val2 == 1 || .@val2 == 2 || .@val2 == 3))
  28.         return(sprintf("%dth", getarg(0)));
  29.  
  30.     switch (.@val2) {
  31.     case 1: return(sprintf("%dst", getarg(0)));
  32.     case 2: return(sprintf("%dnd", getarg(0)));
  33.     case 3: return(sprintf("%drd", getarg(0)));
  34.     default: return(sprintf("%dth", getarg(0)));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement