Solved

Extract a pice of text.

Posted on 2001-09-03
4
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 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