I want to keep user from entering character > ASCII 127 in one of the password field in installer.
我想让用户在安装程序的密码字段之一中输入字符> ASCII 127。
I googled but didn't find any direct way for this, currently i'm using:
我用谷歌搜索,但没有找到任何直接的方式,目前我正在使用:
CHAR ch;
STRING ASCII;
NUMBER nASCII;
for nCount = 0 to StrLength(sPassword)
ch = sPassword[nCount];
sprintf(ASCII,"%d",ch);
StrToNum(nASCII,ASCII);
if ( nASCII > 127 )
MessageBox("Invalid Character in Password",INFORMATION);
endif;
endfor;
Is there any better way to get ASCII code from a string?
有没有更好的方法从字符串中获取ASCII代码?
1 个解决方案
#1
1
First off, I would avoid the conversion to and from string; just compare sPassword[nCount]
with 127
directly; InstallScript stores wide chars (16-bit numbers).
首先,我会避免转换为字符串;只是直接将sPassword [nCount]与127进行比较; InstallScript存储宽字符(16位数字)。
As an alternative approach, you might try calling WideCharToMultiByte with the US-ASCII code page (20127). I'm not that strong with InstallScript and am coding without the compiler, so you might have to fix an error or two, but here's the rough idea:
作为替代方法,您可以尝试使用US-ASCII代码页调用WideCharToMultiByte(20127)。我没有那么强大的InstallScript和没有编译器的编码,所以你可能需要修复一两个错误,但这是一个粗略的想法:
#define CP_US_ASCII 20127
extern prototype NUMBER Kernel32.WideCharToMultiByte(NUMBER, NUMBER, WSTRING, NUMBER, STRING, NUMBER, STRING, BYREF BOOL);
function BOOL IsSafeAscii(STRING szCheck)
STRING szOut;
BOOL bReplaced;
begin
WideCharToMultiBute(CP_US_ASCII, // only supports characters 0-127
WC_NO_BEST_FIT_CHARS, // or maybe 0; disallow turning accented to plain
szCheck, // test string
StrLength(szCheck), // length of test string
szOut, // return buffer
StrLength(szOut), // length of return buffer
"?", // replacement for unsupported characters
bReplaced); // whether replacement was used
return !bReplaced;
end;
#1
1
First off, I would avoid the conversion to and from string; just compare sPassword[nCount]
with 127
directly; InstallScript stores wide chars (16-bit numbers).
首先,我会避免转换为字符串;只是直接将sPassword [nCount]与127进行比较; InstallScript存储宽字符(16位数字)。
As an alternative approach, you might try calling WideCharToMultiByte with the US-ASCII code page (20127). I'm not that strong with InstallScript and am coding without the compiler, so you might have to fix an error or two, but here's the rough idea:
作为替代方法,您可以尝试使用US-ASCII代码页调用WideCharToMultiByte(20127)。我没有那么强大的InstallScript和没有编译器的编码,所以你可能需要修复一两个错误,但这是一个粗略的想法:
#define CP_US_ASCII 20127
extern prototype NUMBER Kernel32.WideCharToMultiByte(NUMBER, NUMBER, WSTRING, NUMBER, STRING, NUMBER, STRING, BYREF BOOL);
function BOOL IsSafeAscii(STRING szCheck)
STRING szOut;
BOOL bReplaced;
begin
WideCharToMultiBute(CP_US_ASCII, // only supports characters 0-127
WC_NO_BEST_FIT_CHARS, // or maybe 0; disallow turning accented to plain
szCheck, // test string
StrLength(szCheck), // length of test string
szOut, // return buffer
StrLength(szOut), // length of return buffer
"?", // replacement for unsupported characters
bReplaced); // whether replacement was used
return !bReplaced;
end;