[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Extract a pice of text.

Posted on 2001-09-03
4
Medium Priority
?
171 Views
Last Modified: 2012-05-04
I have a text that could look like this:

<topnode><header/><images><image type="0501">EXPVIEW/PRODUCT/3000/30177.gif</image><image type="0601">EXPVIEW/HYDRAUL/3000/30906.gif</image></images></topnode>

I like to extract the path to the images and add them to a dyn array.

It might be more than just this two images.
so I like to extract everything between:

> and </image> (where > is the end of the image type="xxxx"> tag.)
0
Comment
Question by:hulken
  • 3
4 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6449928
function ParseString(str:Ansistring):Tstrings;
var res:Tstringlist;
    position:integer;
    offset:integer;
    Closer:integer;
    itemstr:string;
begin
   if str<>'' then
   begin
     res:=Tstringlist.create;
     While Pos(Uppercase('Image Type'),Uppercase(str))>0 do
     begin
       ///find the first '>' after imageType
       position:=Pos(Uppercase('Image Type'),Uppercase(str));
       delete(str,1,position);
       offset:=Pos('>',Str);
       delete(str,1,offset);
       Closer:=Pos(uppercase('</image>'),Uppercase(str));
       itemstr:=copy(str,1,closer-1);
       res.add(itemstr);
       delete(str,1,length(itemstr));
     end;
     result:=res;
   end;
 end;

0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 400 total points
ID: 6449932
ooops.... forgot to put an example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Listbox1.items:=Parsestring('<topnode><header/><images><image type="0501">EXPVIEW/PRODUCT/3000/30177.gif</image><image type="0601">EXPVIEW/HYDRAUL/3000/30906.gif</image></images></topnode>');
end;

Good luck!!

0
 

Author Comment

by:hulken
ID: 6449963
How do I get the result into a dynamic array of Text ?
I like to be able to get the first result with urls[0]
(btw, how can I know the lengt of the array?, I mean how many items it contains)
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6450030
use a TstringList:

Example:

var lst:Tstringlist;
begin
  lst:=tstringlist.create;
  lst.AddStrings(Parsestring('<topnode><header/><images><image type="0501">EXPVIEW/PRODUCT/3000/30177.gif</image><image type="0601">EXPVIEW/HYDRAUL/3000/30906.gif</image></images></topnode>'));
  ShowMessage('there are '+inttostr(lst.count)+' items in the list');
  ShowMessage(lst[0]);
  Showmessage(lst[1]);
  end;


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 4 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question