Asc: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
mNo edit summary
Line 17: Line 17:
</highlight-nsis>
</highlight-nsis>


== The Function ==
<highlight-nsis>
<highlight-nsis>
!macro Asc _STRING _RETURN
!macro Asc _STRING _RETURN
Line 37: Line 38:
!define Asc "!insertmacro Asc"
!define Asc "!insertmacro Asc"


== The Function ==
Function Asc
Function Asc
; Returns an Integer representing the character code corresponding to the first letter in a string.
; Returns an Integer representing the character code corresponding to the first letter in a string.

Revision as of 05:44, 12 August 2005

Author: nechai (talk, contrib)


Description

Returns an Integer representing the character code corresponding to the first letter in a string.

Syntax

${Asc} "String"

"String"   ; string argument

Stack 1    ; Ascii code

Usage

 ${Asc} "a" $0 ; returns 97 in $0
 ${Asc} "AA" $0 ; returns 65 in $0

The Function

!macro Asc _STRING _RETURN
   ; save global registers
   Push $0
   Push $1
   Push $2
   Push $3     
   ; store parameter
   Push ${_STRING}
   Call Asc        
   ; restore global register         
   Pop $3
   Pop $2
   Pop $1
   Exch $0
   Pop ${_RETURN}
!macroend
 
!define Asc "!insertmacro Asc"
 
Function Asc
; Returns an Integer representing the character code corresponding to the first letter in a string.
; 
; Syntax:
; ${Asc} "String" "Return"
; 
; "String"   ; string argument
; "Return"   ; Variable where the ASCII code is returned. The function returns -1 if no ASCII code was found.
; 
; e.g.
; ${Asc} "a" $0 ; returns 97 in $0
; ${Asc} "AA" $0 ; returns 65 in $0
;
 
    ; get parameter
    Pop $1 ; CHAR
    StrCpy $1 $1 1
 
    IntOp $0 0 + 0
    Asc.Do:
        IntFmt $2 %c $0
        System::Call 'kernel32::lstrcmpA(t, t) i(r1,r2) .r3'
        StrCmp $3 "0" Asc.Exit
        IntOp $0 $0 + 1
    StrCmp $0 256 0 Asc.Do
    StrCpy $0 "-1"
 
    Asc.Exit:
 
FunctionEnd