Solved

Parsing a String

Posted on 2003-11-05
6
432 Views
Last Modified: 2008-02-01
Hello, I hvae a String with following format (From IdImap4 Mailboxlist:Mailbox/Sub) XXXX/YYYY, I would get the left Side in Sting1, and right side String 2. Could you help me there?
0
Comment
Question by:k4hvd77
6 Comments
 
LVL 5

Expert Comment

by:snehanshu
ID: 9685374
k4hvd77,
  Can you explain what is your criteria here for the left side and right side?
...Snehanshu
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 9685470
I suppose you could use the Pos-Function to determine the position of the 'Break'-Character.
Example :

- Place 1 TButton and 2 TEdits on a Form.
- In the private section of the unit declare following function :
      function SplitString( SplitChar: String ; Source:String ; var Part1:String ; var Part2: String ): Integer;

- Put following code in the OnClick-Event of the button :

procedure TForm1.Button1Click(Sender: TObject);
var
  strSource : String;
  strP1, strP2 : String;
begin
  strSource  := '(From IdImap4 Mailboxlist:Mailbox/Sub) XXXX/YYYY';
  SplitString(')', strSource, strP1, strP2);
  Edit1.Text := strP1;
  Edit2.Text := strP2;
end;



function TForm1.SplitString( SplitChar: String ; Source: String; var Part1, Part2: String ): Integer;
begin
  Result := Pos(SplitChar, Source);
  Try
        Part1 := Copy( Source, 1, Result );
        Part2 := Copy( Source, Result+1, Length(Source) );
  except
    Result := 0;
  end;
end;


Hope te be of some help
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9685489
something like this?

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function splitstr(var astring : String; Delimiter : String) : String;
var
  p : Integer;
begin
  result := '';
  if AString <> '' then
  begin
    p := pos(Delimiter,AString);
    if p > 0 then
    begin
      result := copy(AString,1,p-1);
      AString := copy(AString,p+length(Delimiter),maxLongInt);
    end
    else
    begin
      result := AString;
      AString := '';
    end;
  end;
end;



procedure TForm1.Button1Click(Sender: TObject);
var s1, s2 : string;
begin
  //discard front of 'From IdImap4 Mailboxlist:Mailbox/Sub'
  //containd in edit1
  s1 := edit1.Text;
  splitstr(s1,':');
  //s1 contains now 'Mailbox/Sub'
  //get the front part
  s2 := splitstr(s1,'/');
  //s2 contains now front part, s1 the rest
  edit2.Text := s2;  //fronpartdisplay
  edit3.Text := s1;  //rest display

end;

end.

meikl ;-)
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 5

Expert Comment

by:DeerBear
ID: 9685831
Hi,

If you have Delphi6, you can use TStringList with DelimitedText to
split the string.

HTH,

Andrew
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 150 total points
ID: 9690356
Try this real cool technique...Very FAST, too.

var
  MyStr: String;
  MyParser: TParser;
  MS: TMemoryStream;
begin
  MyStr := '(From IdImap4 Mailboxlist:Mailbox/Sub) XXXX/YYYY';
  MS := TMemoryStream.Create;
  MS.Position := 0;
  MS.Write(MyStr[1], Length(MyStr));
  MS.Position := 0;
  MyParser := TParser.Create(MS);
  MyStr := MyParser.TokenString;
  while MyParser.Token <> toEOF do
  begin
    if MyParser.TokenSymbolIs(MyParser.TokenString) then
    begin
      MyStr := MyParser.TokenString;
      ShowMessage(MyStr);
    end;
    MyParser.NextToken;
  end;
  MyParser.Free;
  MS.Free;
end;
0
 
LVL 6

Expert Comment

by:swift99
ID: 9691844
slashLoc := pos('/', inputString);
LeftString := Copy (inputString, 1, pos-1);
RightString := Copy (inputString, pos+1, length (inputString)-pos);
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 83
Delphi selector screen 2 57
Delphi Form ownership 4 53
Controlled Assessment GCSE - desperate help needed 4 50
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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now