Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to remove blocks of text Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
07-Jan-03
Category
Object Pascal-Strings
Language
Delphi All Versions
Views
77
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Christian Cristofori

Never needed to remove blocks of text delimited by words or place holders from a 
text? Or comments, included in brackets, from a string? Here is a useful function 
that does that.

Answer:

Just use this function to remove text between round brackets, or specify a 
different start/end placeholder to remove what you nees. 

1   function RemoveBlocks(Value: string; BeginWidth: string = '('; EndWith: 
2   string = ')'):
3     string;
4   var
5     BeginPoint: Integer;
6     EndPoint: Integer;
7   begin
8     BeginPoint := Pos(BeginWith, Value);
9     EndPoint := Pos(EndWith, Value);
10    while ((BeginPoint > 0) and (EndPoint > BeginPoint)) do
11    begin
12      Delete(Value, BeginPoint, (EndPoint - BeginPoint + 1));
13      BeginPoint := Pos(BeginWith, Value);
14      EndPoint := Pos(EndWith, Value);
15    end;
16    Result := Value;
17  end;
18  
19  for example, you can remove all paragraphs in a HTML source just using this: 
20  
21  MyHTML := RemoveBlocks(MyHTML, '<', '>');
22  
23  You can also improve the function by adding a "case-insensitive" function with 
24  something like this: 
25  
26  function RemoveBlocks(Value: string; BeginWidth: string = '('; EndWith: string = 
27  ')'):
28    string;
29  var
30    BeginPoint: Integer;
31    EndPoint: Integer;
32  begin
33    BeginWith := LowerCase(BeginWith);
34    EndWith := LowerCase(EndWith);
35    BeginPoint := Pos(BeginWith, LowerCase(Value));
36    EndPoint := Pos(EndWith, LowerCase(Value));
37    while ((BeginPoint > 0) and (EndPoint > BeginPoint)) do
38    begin
39      Delete(Value, BeginPoint, (EndPoint - BeginPoint + 1));
40      BeginPoint := Pos(BeginWith, LowerCase(Value));
41      EndPoint := Pos(EndWith, LowerCase(Value));
42    end;
43    Result := Value;
44  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC