Solved

Extract a pice of text.

Posted on 2001-09-03
4
147 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Get height of a forms top border. 3 32
TcomboBox uninverted item 3 44
Delphi TcxGrid group footer summary 3 143
Multiple image collision 13 42
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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now