问题描述
我让我的函数确定WideChar var是否为字母:
function TWordCounter.IsAlpha(ch: WideChar): boolean;
Begin
ch := upcase(ch);
isalpha := (((ch >='A') and (ch <='Z')) or ((ch >='А') and (ch <='Я')));
end;
Procedure TWordCounter.CountWords(path: string);
var
inputFile: TextFile;
chr: WideChar;
inWord: boolean;
currentWord: string[MAX_WORD_LENGTH];
Begin
SetLength(wordArray,0);
if (not FileExists(path)) then begin
raise Exception.Create('Указанный путь не ведет к текстовому файлу');
exit;
end;
SetLength(wordArray,BASE_WORD_ARRAY_LENGTH);
currentArrayLimit := BASE_WORD_ARRAY_LENGTH;
currentArrayLength := 0;
AssignFile(inputFile,path);
Reset(inputFile);
inWord := false;
currentWord := '';
while not eof(inputFile) do begin
read(inputFile,chr);
if (isAlpha(chr)) then begin
inWord := true;
currentWord := currentWord + chr;
end
else begin
if (inWord) then begin
AddToDictionary(currentWord);
currentWord := '';
end;
inWord := false;
end;
end;
SetLength(wordArray,currentArrayLength);
CloseFile(inputFile);
end;
我也使用{$codepage UTF8}
编译器指令。读取文件中有WideChar(2字节)俄语符号,我无法像上面的(*read(inputFile,chr)*)
那样使用它们,好像我只用这种方式读取了符号的第一个字节。如果我直接将一些符号分配给WideChar
变量,然后调用IsAlpha函数,则它会很好地工作,例如:
chr: WideChar;
chr := 'Й';
IsAlpha(chr); // true
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)