?
Solved

Getting a piece of text out of other text

Posted on 2004-10-09
5
Medium Priority
?
193 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 300 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

Industry Leaders: 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

770 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