Alphabet Identifier ( $alph() )

By Pepsi_Man0077 on Apr 03, 2009

I looked around and couldnt find an appropriate built-in identifier that works with the english aplhabet. So i decided to make one. This script takes an alphabetical character and puts it in numerical form, or vise versa. See below for some examples

Syntax: $alph(L,A,etc)
N = Alphabetical Number (1 = a, 26 = z)
L = Number from Alphabetical Characters (a = 1, z = 26)

Usage Examples:

[u]$alph(1)
This would return "a" without the quotes[/u]

[b]$alph(a)
This would return "1" without the quotes[/b]

[u]$alph(1-z)
This would return "a-26" without the quotes[/u]

[b]$alph(1,2,3,4,5,f,g,h,i,j)
This would return "a b c d e 6 7 8 9 10" without the quotes[/b]

[u]$alph(1,7).list
This would return "a b c d e f g" without the quotes[/u]

[b]$alph(a,h).list
This would return "1 2 3 4 5 6 7 8" without the quotes[/b]

By default, all Alphabetical letters are returned in lower-case form

This identifier can be very useful in loops

Ex:

alias listalpha {
  if (!$2) { halt }
  if ($1 isnum) || ($2 isnum) { halt }
  var %start $alph($1)
  var %end $alph($2)
  while (%start <= %end) {
    echo -a $alph(%start)
    inc %start
  }
}

When this is in remotes, and you type "/listalpha a z" without quotes
It will return every alphabetical number from a to z on separate lines

alias alph {
  var %num.a 1 | var %num.b 2 | var %num.c 3 | var %num.d 4 | var %num.e 5 | var %num.f 6 | var %num.g 7 | var %num.h 8 | var %num.i 9 | var %num.j 10 | var %num.k 11 | var %num.l 12 | var %num.m 13
  var %num.n 14 | var %num.o 15 | var %num.p 16 | var %num.q 17 | var %num.r 18 | var %num.s 19 | var %num.t 20 | var %num.u 21 | var %num.v 22 | var %num.w 23 | var %num.x 24 | var %num.y 25 | var %num.z 26
  var %let.1 a | var %let.2 b | var %let.3 c | var %let.4 d | var %let.5 e | var %let.6 f | var %let.7 g | var %let.8 h | var %let.9 i | var %let.10 j | var %let.11 k | var %let.12 l | var %let.13 m
  var %let.14 n | var %let.15 o | var %let.16 p | var %let.17 q | var %let.18 r | var %let.19 s | var %let.20 t | var %let.21 u | var %let.22 v | var %let.23 w | var %let.24 x | var %let.25 y | var %let.26 z
  if ($1 isnum) && ($1 < 27) && (!$2) {
    return %let. [ $+ [ $1 ] ]
  }
  elseif ($1 isalpha) && (!$2) {
    return %num. [ $+ [ $1 ] ]
  }
  elseif (!$2) && ($numtok($1,45) == 2) {
    if ($gettok($1,1,45) isnum) && ($gettok($1,1,45) > 26) { goto end }
    if ($gettok($1,2,45) isnum) && ($gettok($1,2,45) > 26) { goto end }
    return $+($iif($gettok($1,1,45) isalpha,%num. [ $+ [ $gettok($1,1,45) ] ],%let. [ $+ [ $gettok($1,1,45) ] ]),-,$iif($gettok($1,2,45) isalpha,%num. [ $+ [ $gettok($1,2,45) ] ],%let. [ $+ [ $gettok($1,2,45) ] ]))
  }
  elseif (!$3) && ($prop == list) {
    if ($len($gettok($1-,1,32)) > 2) && ($1 isalpha) && ($2 isalpha) { goto end }
    if ($1 isnum) && ($1 > 26) { goto end }
    if ($2 isnum) && ($2 > 26) { goto end }
    var %start $1
    var %end $2
    if ($1 isnum) && ($2 isnum) { while (%start <= %end) { if (!%result) { var %result = %let. [ $+ [ %start ] ] } | elseif (%result) { var %result = %result %let. [ $+ [ %start ] ] } | inc %start } | return %result }
    elseif ($1 isalpha) && ($2 isalpha) { var %start = %num. [ $+ [ %start ] ] | var %end = %num. [ $+ [ %end ] ] | while (%start <= %end) { if (!%result) { var %result = %num. [ $+ [ %let. [ $+ [ %start ] ] ] ] } | elseif (%result) { var %result = %result %num. [ $+ [ %let. [ $+ [ %start ] ] ] ] } | inc %start } | return %result }
  }
  else { var %x 1 | var %lo.prop $1- | while (%x <= $numtok(%lo.prop,32)) { if ($gettok(%lo.prop,%x,32) > 26) && ($gettok(%lo.prop,%x,32) isnum) { goto end } | if ($len($gettok(%lo.prop,%x,32)) > 1) && ($gettok(%lo.prop,%x,32) isalpha) { goto end } | if (!%result) { var %result = $iif($gettok(%lo.prop,%x,32) isalpha,%num. [ $+ [ $gettok(%lo.prop,%x,32) ] ],%let. [ $+ [ $gettok(%lo.prop,%x,32) ] ]) } | elseif (%result) { var %result = %result $iif($gettok(%lo.prop,%x,32) isalpha,%num. [ $+ [ $gettok(%lo.prop,%x,32) ] ],%let. [ $+ [ $gettok(%lo.prop,%x,32) ] ]) } | if (%x = $numtok(%lo.prop,32)) { return %result } | inc %x } }
  :end
}

Comments

Sign in to comment.
Jethro   -  Aug 15, 2010

BigSteve, you should send a PM to hawkee regarding this matter and have your password reset. Whoever tampered with your account made you look maliciously bad. I'm sure Hawkee can match the IP addresses between you and the hacker (though I wouldn't call him or her a hacker anyway; your password may be too easy to guess and be leaked) to find out what was going on.

 Respond  
Snip3KitTy   -  Aug 15, 2010

Would be good to use this script to make a follow up Bingo game to go with this script, i feel it would go quit well as the bingo numbers are things like I-25 and stuff so the $alph() will work perfectly for such a script

 Respond  
BlueThen   -  Apr 08, 2009

For letter to number, you could have just taken the ascii value of the lowercase letter and subtracted 96 (since 97 is a)

$calc($asc($lower(L)) - 96)

Replace L with whatever letter of course.

And vice-versa by using $chr of whatever number plus 96.

$chr($calc(n+96))

Replace n with whatever number

 Respond  
Pepsi_Man0077   -  Apr 08, 2009

Ok, let me know how it goes.

 Respond  
Blitzjager   -  Apr 05, 2009

When I first saw it I couldn't think of a use for it but then I needed something like it for a hex thing. I decided this was a bit much for what I needed(A-F) but I was going to use it.

 Respond  
Pepsi_Man0077   -  Apr 04, 2009

Thank you Aucun50 :)

 Respond  
Aucun50   -  Apr 04, 2009

Very neat, i like how you can do a to number and 1 to letters also the list option is great.

Great Script

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.