最近学习NSIS安装,设计和用户交互,让用户输入用户秘密,输入的时候相对用户的输入做一些限制,就对输入的字符串进行判断,发现NSIS脚本中没有字符比较,只能用ascii码了
1 !define CharToASCII "!insertmacro CharToASCII"
2
3 !macro CharToASCII AsciiCode Character
4 Push "${Character}"
5 Call CharToASCII
6 Pop "${AsciiCode}"
7 !macroend
8
9 Function CharToASCII
10 Exch $0 ; given character
11 Push $1 ; current character
12 Push $2 ; current Ascii Code
13
14 StrCpy $2 1 ; right from start
15 Loop:
16 IntFmt $1 %c $2 ; Get character from current ASCII code
17 ${If} $1 S== $0 ; case sensitive string comparison
18 StrCpy $0 $2
19 Goto Done
20 ${EndIf}
21 IntOp $2 $2 + 1
22 StrCmp $2 255 0 Loop ; ascii from 1 to 255
23 StrCpy $0 0 ; ASCII code wasn't found -> return 0
24 Done:
25 Pop $2
26 Pop $1
27 Exch $0
28 FunctionEnd