如何在RichEdit中查找一个中文字串(100分)

  • 主题发起人 主题发起人 findjob168
  • 开始时间 开始时间
F

findjob168

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在RichEdit中查找一个中文字串,我用with RichEditor do FindDialog(SelText);
只能查找英文字串,而不能查找中文字串,如何解?急!!!
 
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
str:string;


with RichEdit do begin
str:='查找的中文字串';
FoundAt := FindText(str, StartPos, ToEnd, [stMatchCase]);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(str);
SelAttributes.color:=clred;
end;
end;
 
用循环查找啊,自己写个窗口,
 
代码如下:Pos('你',RichEdit1.text)>=0 说明找到这个字符了
 
procedure TfrmMain.RepCodeFind(Sender: TObject);
Var
intPos,intPAt:integer;
begin
//intCurLine:=memoCode.Perform(EM_LINEFROMCHAR, -1, 0);

With memoCode do
Begin
intPAt:=SelStart+SelLength;
intPos:=Position(RepCode.FindText,Copy(Text,SelStart+SelLength,Length(Text)),1);
intPos:=intPAt+intPos;
if intPos>0 then
Begin
SelStart:=intPos-2;
SelLength:=Length(RepCode.FindText);
//滚动 RichText 以显示找到的文字
Perform(EM_SCROLLCARET, 0 , 0);
End
Else
Begin
Application.MessageBox(Pchar('搜索完毕!'),Pchar('搜索'),MB_OK+MB_ICONINFORMATION);
SelStart:=0;
End;
//SetFocus;
End;
end;

Position 是自定义函数
function TfrmMain.Position(SubStr, SourceStr: string;
intOccur: integer): integer;
var
//intProvPos:integer;
//intLastPos:integer;
intSubLength:integer;
intSourceLength:integer;
intOccurNo:integer;
intI:integer;
strFind:String;
begin
if intOccur<1 then
begin
MessageBox(0,Pchar('参数错误,参数intOccur应大于0'),Pchar('参数'),MB_OK+MB_ICONWARNING+MB_TASKMODAL);
Result:=0;
exit;
end;
intSubLength:=Length(SubStr);
intSourceLength:=Length(SourceStr);
intOccurNo:=0;
for intI := 1 to intSourceLength do
Begin
strFind:=Copy(SourceStr,intI,intSubLength);
if strFind=SubStr then
begin
intOccurNO:=intOccurNO+1;
if intOccurNO=intOccur then
begin
Position:=intI;
exit;
end;
end;
end;
Position:=0;
End;

 
后退
顶部