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

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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