CharToASCII: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(One intermediate revision by one other user not shown) | |||
Line 7: | Line 7: | ||
== Requirements == | == Requirements == | ||
'''Requires:''' [[LogicLib]]. | '''Requires:''' [[LogicLib header file]]. | ||
<highlight-nsis> | <highlight-nsis> | ||
!define LOGICLIB_STRCMP | !define LOGICLIB_STRCMP | ||
Line 65: | Line 65: | ||
IntOp $2 $2 + 1 | IntOp $2 $2 + 1 | ||
StrCmp $2 255 0 Loop ; ascii from 1 to 255 | StrCmp $2 255 0 Loop ; ascii from 1 to 255 | ||
StrCpy $0 0 ; ASCII code | StrCpy $0 0 ; ASCII code wasn't found -> return 0 | ||
Done: | Done: | ||
Pop $2 | Pop $2 |
Latest revision as of 09:47, 15 November 2009
Author: Mæster (talk, contrib) |
Description
This function returns the ASCII code number for a given character.
Requirements
Requires: LogicLib header file.
!define LOGICLIB_STRCMP !include LogicLib.nsh
How To Use
Syntax
${CharToASCII} $ResultVar "Character"
or
Push "Character" Call CharToASCII Pop $ResultVar
Parameters
- ResultVar
- Variable where the ASCII code is returned. The function returns 0 if no ASCII code was found.
- Character
- The Character for ASCII conversation
Example
${CharToASCII} $0 "T" ;$0 = 84
Function Code
!define CharToASCII "!insertmacro CharToASCII" !macro CharToASCII AsciiCode Character Push "${Character}" Call CharToASCII Pop "${AsciiCode}" !macroend Function CharToASCII Exch $0 ; given character Push $1 ; current character Push $2 ; current Ascii Code StrCpy $2 1 ; right from start Loop: IntFmt $1 %c $2 ; Get character from current ASCII code ${If} $1 S== $0 ; case sensitive string comparison StrCpy $0 $2 Goto Done ${EndIf} IntOp $2 $2 + 1 StrCmp $2 255 0 Loop ; ascii from 1 to 255 StrCpy $0 0 ; ASCII code wasn't found -> return 0 Done: Pop $2 Pop $1 Exch $0 FunctionEnd