Solved

Extract a pice of text.

Posted on 2001-09-03
4
149 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 100 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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