We are working on converting the wiki to a static website controlled by markdown files in https://github.com/nsis-community. You can already see there how plug-ins will be posted. The end-user interface will still be a website but with a fresh coat of paint. Come meet us at Discord to talk about it.
CharToASCII
From NSIS Wiki
Jump to navigationJump to search
| 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