Solved

Extract a pice of text.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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