$getasc

By Roy_ on Oct 03, 2007

; $getasc - Roy
; Credits
; -------
; This snippet may appear similar to Lindrian's $asc
snippet, part of the snippet actually does what Lindrian's snippet does.
; I give credit to Lindrian for the original idea of the $chr demo.
; -------
; Usage
; -------
; $getasc(string).dem/chrform or nothing at all
; dem returns the string in a (chr) = (chr num) format
; chrform returns the string $chr(chr num) format
; or you can just get the chr values with no property
; -------
; --Roy

; See in-code examples for a better idea on how to use it.

; $getasc - Roy_
; Usage
; -------
; $getasc(string).dem/chrform or nothing at all
; dem returns the string in a (chr) = (chr num) format
; chrform returns the string $chr(chr num) format
; or you can just get the chr values with no property
; -------
; Examples
; -------
; //echo -a $getasc(test) -> 116 101 115 116
; //echo -a $getasc(test).dem -> t = 116 e = 101 s = 115 t = 116
; //echo -a $getasc(test).chrform -> $chr(116) $chr(101) $chr(115) $chr(116)
; -------

alias getasc { 
  if ($isid) && ($1-) { 
    if ($prop = dem) { 
      var %a $1-, %b $len($1-), %c 1 
      while (%c <= %b) { 
        var %t = $+(%t,$chr(32),$mid(%a,%c,1),$chr(32),=,$chr(32),$asc($mid(%a,%c,1)))
        inc %c
      }
      return %t
    }
    if ($prop = chrform) { 
      var %a $1-, %b $len($1-), %c 1 
      while (%c <= %b) { 
        var %t = $+(%t,$chr(32),$,$+(chr,$chr(40),$asc($mid(%a,%c,1)),$chr(41)))
        inc %c
      }
      return %t
    }
    elseif (!$prop) { 
      var %a $1-, %b $len($1-), %c 1 
      while (%c <= %b) { 
        var %t = $+(%t,$chr(32),$asc($mid(%a,%c,1)))
        inc %c
      }
      return %t
    }
  }
}

Comments

Sign in to comment.
guest598594   -  Oct 04, 2007

u could shorten it eve more by doin

if ($isid && $1) {
 Respond  
KuTsuM   -  Oct 03, 2007

You should shorten this:
if ($isid) {
if ($1-) {
to
if ($isid) && ($1-) {

Also using the = in the var command I beleive allows you to add more length to variable (I heard this somewhere on here a while back)

 Respond  
RubixCube   -  Oct 03, 2007

Nice, but I don\'t see a use for this other than retrieving values of characters. That can easily be done manually, but good job nonetheless .

 Respond  
Scakk   -  Oct 03, 2007

After I added the \" = \" in all three places it worked.

/me shrugs

 Respond  
Roy_   -  Oct 03, 2007

Hmm, alright. But that shouldn\'t really make a difference. As far as I know at least. Will do Scakk.

--Roy

 Respond  
Roy_   -  Oct 03, 2007

Interesting, they all seemed to work fine for me. I\'ll check the code again and find the issue.

 Respond  
Scakk   -  Oct 03, 2007

Change the

var %t $+ 

to

var %t = $+

And it will work.

 Respond  
Scakk   -  Oct 03, 2007

I tried the examples you gave and got

* Invalid format: $+ (line 33, WaiterJohn)
-
* Invalid format: $+ (line 25, WaiterJohn)
-
* Invalid format: $+ (line 41, WaiterJohn)
-
 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.