{从字符串中提取单词的函数} 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; |