gpt4 book ai didi

delphi - 检查字符是否为换行符

转载 作者:行者123 更新时间:2023-12-03 15:52:50 30 4
gpt4 key购买 nike

你好,我有一个简单的程序,它计算给定文本中的字符,直到行为空行,仅包含新行

var
znaki: array['a'..'z'] of integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
napis: String;
maly: String;
dlugosc: Integer;
znak: char;


begin
napis := 'a';
while napis[1] <> '#13#10'do
begin
readln(napis);
maly:=LowerCase(napis);
for dlugosc:=(length(maly)) downto 1 do
begin
znaki[maly[dlugosc]]:=znaki[maly[dlugosc]]+1;
end;
for znak:='a' to 'z' do
writeln(znak, ' ', znaki[znak]);
end;

end.

它在 while 条件下失败,我不知道为什么。请给我线索

最佳答案

一个字符,napis[1];不能是 2 个字符 #13#10...

所以,我会这样做:

var
znaki: array['a'..'z'] of integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
napis: String;
maly: String;
dlugosc: Integer;
znak: char;


begin
napis := 'a';
while ((Length(napis) > 0)) do
begin
readln(napis);
// napis := StringReplace(napis, #13#10, #10, [rfReplaceAll]); //useless for a console readln
maly:=LowerCase(napis);
for dlugosc:=(length(maly)) downto 1 do
begin
znaki[maly[dlugosc]]:=znaki[maly[dlugosc]]+1;
end;
for znak:='a' to 'z' do
writeln(znak, ' ', znaki[znak]);
end;
end.

关于delphi - 检查字符是否为换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10598365/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com