Solved

Getting a piece of text out of other text

Posted on 2004-10-09
5
190 Views
Last Modified: 2013-12-03
Hey there,

I have some text and I want to copy some parts out of it.
Basically, the text is this.

<a href="#" onclick="return !showPopup(th_name, event,Persons name.');">?</a> <font color="darkblue">Name:</font> <div align="right">Robert&nbsp;</div>
<a href="#" onclick="return !showPopup(th_adddy, event,'addy.');">?</a> <font color="darkblue">Address:</font> <div align="right">Over rainbow&nbsp;</div>
<a href="#" onclick="return !showPopup(th_ph, event,personsphone.');">?</a> <font color="darkblue">Phone:</font> <div align="right">8751nbsp;</div>

So what I would want to do, if located the Name and then get there actual name. So is the best way to get postion of "Name:</font> <div align="right">" then get the characters between that and & - so i'd end up with Robert.....

Is that the best way?
0
Comment
Question by:wildzero
[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
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
sftweng earned 75 total points
ID: 12265868
unit uQ_21161984;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    EditSource: TEdit;
    EditStart: TEdit;
    EditStop: TEdit;
    EditResult: TEdit;
    ButtonExtract: TButton;
    procedure ButtonExtractClick(Sender: TObject);
    function StringExtract(aSource, aStartDelim, aStopDelim : String) : String;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.StringExtract(aSource, aStartDelim, aStopDelim : String) : String;
var
  workString : String;
  resultString : String;
  startPos, stopPos : Integer;
begin
  workString := aSource;
  resultString := '';
  startPos := Pos(aStartDelim,workString);
  if (startPos > 0)
  then begin
    Delete(workString,1,startPos+Length(aStartDelim)-1);
    stopPos := Pos(aStopDelim,workString);
    if (stopPos > 0)
    then begin
      workString := Copy(workString,1,stopPos-1);
    end; {if}
    resultString := workString;
  end {if};
  StringExtract := workString;
end; {StringExtract}

procedure TForm1.ButtonExtractClick(Sender: TObject);
var
  str : String;
begin
  EditResult.Text := StringExtract(EditSource.Text,
                                   EditStart.Text,
                                   EditStop.Text);
end {ButtonExtractClick};

end.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12265876
Oops - last line of String Extract should be:
  StringExtract := resultString;
0
 
LVL 10

Author Comment

by:wildzero
ID: 12269640
Hey sftweng,

Sorry for taking so long to get back to you.
That worked ok, except - for my text I provided what should I use for start/stop delimters?

Because having a start delimter of > will be totally unsuitable, and using 'Name:</font> <div align="right">' just returns nothing.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12269721
Here's the *.dfm I used:

object Form1: TForm1
  Left = -2
  Top = 110
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object EditSource: TEdit
    Left = 64
    Top = 40
    Width = 497
    Height = 21
    TabOrder = 0
    Text =
      '<a href="#" onclick="return !showPopup(th_name, event,Persons na' +
      'me.'#39');">?</a> <font color="darkblue">Name:</font> <div align="ri' +
      'ght">Robert&nbsp;</div>'
  end
  object EditStart: TEdit
    Left = 64
    Top = 72
    Width = 497
    Height = 21
    TabOrder = 1
    Text = 'Name:</font> <div align="right">'
  end
  object EditStop: TEdit
    Left = 64
    Top = 104
    Width = 497
    Height = 21
    TabOrder = 2
    Text = '&nbsp'
  end
  object EditResult: TEdit
    Left = 64
    Top = 136
    Width = 497
    Height = 21
    TabOrder = 3
  end
  object ButtonExtract: TButton
    Left = 64
    Top = 168
    Width = 75
    Height = 25
    Caption = 'Extract'
    TabOrder = 4
    OnClick = ButtonExtractClick
  end
end
0
 
LVL 10

Author Comment

by:wildzero
ID: 12273861
Ah how right you were

Reason it didn't work for me was cos of WordWrap on the Tmemo.
Sorted now - many thanks!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 48
Press three keys together and trigger a function 3 67
Convert MS Word document to a PDF file 9 115
Dynamically Created Query 3 70
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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

730 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