如何验证在 delphi 控制台应用程序中是否从 qwerty 键盘输入了连续的字母?
How can one verify whether consecutive letters have been entered from the qwerty keyboard in a delphi console application?
基本上,我有一个输入,我想验证用户输入是否使用了 3 个或更多来自 qwerty 键盘布局的连续字母。我的意思是 Q-W-E 或 Y-U-I-O-P。首先,我将用户输入存储在一个字符串变量中,并使用 ansiLowerCase 函数将输入转换为小写。我搞砸了将 qwerty 布局声明为常量字符串并使用 strscan 函数但无济于事。非常感谢任何帮助,谢谢。
尝试这样的事情:
function HasThreeConsecutiveLetters(const Str: string): Boolean;
const
QwertyLetters: array[0..2] of string = (
'QWERTYUIOP',
'ASDFGHJKL',
'ZXCVBNM'
);
var
I, J, K: Integer;
S: String;
begin
Result := False;
S := AnsiUpperCase(Str);
for I := 1 to Length(S) do
begin
for J := Low(QwertyLetters) to High(QwertyLetters) do
begin
K := Pos(S[I], QwertyLetters[J]);
if (K <> 0) and
((K+2) <= Length(QwertyLetters[J])) and
(Copy(S, I, 3) = Copy(QwertyLetters[J], K, 3)) then
begin
Result := True;
Exit;
end;
end;
end;
end;
那么你可以这样做:
var
input: string;
begin
input := ...;
if HasThreeConsecutiveLetters(input) then
...
else
...
end;
基本上,我有一个输入,我想验证用户输入是否使用了 3 个或更多来自 qwerty 键盘布局的连续字母。我的意思是 Q-W-E 或 Y-U-I-O-P。首先,我将用户输入存储在一个字符串变量中,并使用 ansiLowerCase 函数将输入转换为小写。我搞砸了将 qwerty 布局声明为常量字符串并使用 strscan 函数但无济于事。非常感谢任何帮助,谢谢。
尝试这样的事情:
function HasThreeConsecutiveLetters(const Str: string): Boolean;
const
QwertyLetters: array[0..2] of string = (
'QWERTYUIOP',
'ASDFGHJKL',
'ZXCVBNM'
);
var
I, J, K: Integer;
S: String;
begin
Result := False;
S := AnsiUpperCase(Str);
for I := 1 to Length(S) do
begin
for J := Low(QwertyLetters) to High(QwertyLetters) do
begin
K := Pos(S[I], QwertyLetters[J]);
if (K <> 0) and
((K+2) <= Length(QwertyLetters[J])) and
(Copy(S, I, 3) = Copy(QwertyLetters[J], K, 3)) then
begin
Result := True;
Exit;
end;
end;
end;
end;
那么你可以这样做:
var
input: string;
begin
input := ...;
if HasThreeConsecutiveLetters(input) then
...
else
...
end;