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