in Code

NSIS CharAt Macro

Lord knows why the NSIS folks didn’t add a CharAt function to their API.
In case you need it to parse a string, here’s a Macro that makes StrCpy work like a CharAt function

;Get a character inside a string given an index.
;Usage: CharAt String Index Output
!macro CharAt InputString Index Output
StrCpy ${Output} ${InputString} 1 ${Index}

To use the CharAt “function” (macro in this case), do as follows:

!insertmacro CharAt "Hello World!" 1 $0
;$0 will have the letter ‘e’ inside.

Write a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.