I have to search within a TRichView a text preceded by a specific string, in example:
'Word1 Word2 blabla blabla bla bla
more bla bla and more bla bla bla
beginhere0123456789finish'
I Want to extract '0123456789' (10 chars after 'beginhere').
How can I do it? Should I seek with SearchText() first?
Thanks.
How to get n chars (a string) after a string found....
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Sergey, thanks for the answer. With your help I could do the following. I made my own GetNCharsFromSearch() function:
Given a string (in a TRichViewEdit): "Borland has committed suicide. And only remains in our memory."
I call..
GetNCharsFromSearch( RVE, 'land', 27)
I Get = ' has committed suicide. And' (27 chars)
I do not know if this is the best way. This is the code for those who want to take a look.
Given a string (in a TRichViewEdit): "Borland has committed suicide. And only remains in our memory."
I call..
GetNCharsFromSearch( RVE, 'land', 27)
I Get = ' has committed suicide. And' (27 chars)
I do not know if this is the best way. This is the code for those who want to take a look.
Code: Select all
Function GetNCharsFromSearch(
rv : TRichViewEdit ;
Cadena : String ;
NChars : Integer
) : String ;
var No1, No2, Offs1, Offs2: Integer;
Tmp : String ;
NItem : Integer ;
begin
If rv.SearchText( Cadena, [rvseoDown] ) then begin
rv.TopLevelEditor.GetSelectionBounds(No1,Offs1,No2,Offs2,True);
Tmp := rv.TopLevelEditor.GetItemText(No1) ;
Result := Copy(Tmp ,Offs2, (Length(Tmp)-Offs2)+1 ) ;
NItem := No2 ;
While (Length(Result)<NChars) and (NItem<rv.ItemCount) do begin
Inc(NItem) ;
Result := Result + rv.TopLevelEditor.GetItemText(NItem) ;
end ;
Result := Copy(Result,1, NChars) ;
end ;
end ;
...
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Change
to
Also, do you want to accumulate text even if it belons to several paragraphs? If not, add
at the beginning of this cycle.
Code: Select all
While (Length(Result)<NChars) and (NItem<rv.ItemCount) do begin
Inc(NItem) ;
Result := Result + rv.TopLevelEditor.GetItemText(NItem) ;
end
Code: Select all
Inc(NItem) ;
While (Length(Result)<NChars) and (NItem<rv.ItemCount) do begin
if rv.TopLevelEditor.GetItemStyle(NItem)>=0 then
Result := Result + rv.TopLevelEditor.GetItemText(NItem)
else if rv.TopLevelEditor.GetItemStyle(NItem)=rvsTab then
Result := Result + #9;
Inc(NItem) ;
end
Code: Select all
if rv.TopLevelEditor.IsFromNewLine(NItem) then
break;