InstallScript InstallShield 中的字符 ASCII 代码

发布于 2024-12-04 15:43:08 字数 436 浏览 3 评论 0原文

我想阻止用户输入字符 >安装程序中密码字段之一为 ASCII 127。

我用谷歌搜索但没有找到任何直接的方法,目前我正在使用:

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?

I want to keep user from entering character > ASCII 127 in one of the password field in installer.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可是我不能没有你 2024-12-11 15:43:08

首先,我会避免与字符串之间的转换;只需直接将 sPassword[nCount]127 进行比较即可; InstallScript 存储宽字符(16 位数字)。

作为替代方法,您可以尝试调用 WideCharToMultiByte< /a> 与 US-ASCII 代码页 (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;

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).

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:

#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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文