电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

从字符串中提取单词、从字符串中提取汉字的函数


发布日期:2022/1/2
 

{从字符串中提取单词的函数}

procedure StrToWordList(str: string; var List: TStringList); var

p: PChar;

i: Integer;

begin

if List = nil then List := TStringListCreate;

ListClear;

{去除重复}

ListSorted := True;

ListDuplicates := dupIgnore;

p := PChar(str);

{把单词以外的字符转为空格 并把大写字母转小写}

while p^ <> # do

begin

case p^ of

AZ: p^ := Chr(Ord(p^) + );

az : ;

else p^ := #;

end;

Inc(p);

end;

{用空格分离单词到列表}

ListDelimiter := #;

ListDelimitedText := str;

{单词的开头应该是字母 去除其他}

for i := ListCount downto do

begin

if CharInSet(List[i][] [ ]) then

ListDelete(i);

end;

end;

{从字符串中提取汉字的函数}

procedure StrToHanZiList(str: string; var List: TStringList);

var

p: PWideChar;

begin

if List = nil then List := TStringListCreate;

ListClear;

{去除重复}

ListSorted := True;

ListDuplicates := dupIgnore;

p := PWideChar(str);

while p^ <> # do

begin

case p^ of

#$E#$FA: ListAdd(p^);

end;

Inc(p);

end;

end;

上一篇:直接存取文件的方法

下一篇:SDL学习笔记一图片和字体显示