[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

email regexp with extras

Posted on 2004-10-28
7
Medium Priority
?
177 Views
Last Modified: 2011-10-03
Hi all.   I want to do this:

Give a file open box that will open a standard text file and read it as a stream or something (I'm flexible.)  This will be a delimited file that will have the emails from my CoREA mailing list in it.   Depending which version of my server I'm using it will either be comma delimited or pipe | delimited.   I would love to see a function that would extract the emails here and put them in a tstringlist.  Any ideas?

Thanks!
0
Comment
Question by:hibbidiji
[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
  • 2
7 Comments
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12438412
do you mean something like to this code ? :

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var t:textfile;
    s:String;
    list:tstrings;
begin
if opendialog1.Execute then
begin
list:=tstringlist.Create;
assignfile(t,opendialog1.FileName);
reset(t);
while not eof(t) do
  begin
   readln(t,s);
   list.Add(s);
  end;

// show the list in the memo
memo1.lines:=list;
list.Free;
end;
end;

end.




// DFM FILE
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 696
  Height = 480
  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 Button1: TButton
    Left = 263
    Top = 137
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Memo1: TMemo
    Left = 84
    Top = 189
    Width = 457
    Height = 155
    Lines.Strings = (
      'Memo1')
    TabOrder = 1
  end
  object OpenDialog1: TOpenDialog
    Left = 179
    Top = 132
  end
end
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 12438723
I can do that...  opening a txt file and assigning it to a stream or a tstringlist or whatever.  its running through and picking out emails that are comma delimited on each line that i dont know.   I suck at regexp and have no experiance at ALL with it on delphi
0
 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 1000 total points
ID: 12442293
then , what about this code :

function getlist(list1:tstrings;flag:boolean):tstrings; // flag=true it means it's calling from server1
                                                        // flag=false it means it's calling from server2
var i,j:integer;
    templist:tstrings;
begin
 result:=tstringlist.Create;
 templist:=tstringlist.Create;
 templist.Clear;
  result.Clear;

if flag then
  begin  // check for delimited char on SERVER1
  templist.Delimiter:=','; // <---
  for i:=0 to list1.Count-1 do
   begin
   templist.DelimitedText:=list1.Strings[i];
      for j:=0 to templist.count-1 do
        if result.IndexOf(templist.Strings[j])<0 then // for redunduncy check
                  result.Add(templist.Strings[j]);
   end
  end
 else
  begin
  // check for delimited char on SERVER2
  templist.Delimiter:='|'; // <---
  for i:=0 to list1.Count-1 do
   begin
   templist.DelimitedText:=list1.Strings[i];
      for j:=0 to templist.count-1 do
        if result.IndexOf(templist.Strings[j])<0 then // for redunduncy check
                  result.Add(templist.Strings[j]);
   end;
   templist.Free;
  end;

end;

procedure TForm1.Button1Click(Sender: TObject);
var

  FromF: file;
  NumRead: Integer;
  Buf: array[1..2048] of Char;
  list1,mylist:tstrings;
  i:integer;

begin
  if OpenDialog1.Execute then
  begin
   list1:=tstringlist.Create;
   mylist:=tstringlist.Create;

   list1.Clear;
    AssignFile(FromF, OpenDialog1.FileName);
    Reset(FromF, 1);
      repeat
        BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
        buf[numread+1]:=chr(0);
        list1.Text:=list1.Text+buf;
      until (NumRead = 0) ;
   CloseFile(FromF);

// get the list for server1
memo1.Lines:=getlist(list1,true { or false for server2 });

//    or
//    mylist:=getlist(list1,true { or false for server2 })
    end;
end;

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:hibbidiji
ID: 12448408
That does good with the delimiter, but of maybe 10 things in a line, I have to pick out the email.    so I have to go through the templist and do a regular expression check to find the email in the line then pop it into a list.  

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12467045
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 12467272
My problem is that I dont know how to do regexp in delphi. I've never used it there before.  all my regexp experiance is in php
0
 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 1000 total points
ID: 12467993
Download one of the regex controls from Torry's:

Regular Expressions for Delphi by Andrey Sorokin.  
http://www.torry.net/vcl/vcltools/text/regexpr.zip

Pattern String Engine by SoftComplete Development
http://www.torry.net/vcl/vcltools/text/pse.zip

TmkreExpr by M.C. van der Kooij
http://www.torry.net/vcl/vcltools/text/kregex.zip

UCFileGrep by UCSoft
http://www.torry.net/vcl/vcltools/text/ucfg.zip



0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

649 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