Solved

String Parsing...

Posted on 1998-08-31
3
129 Views
Last Modified: 2010-04-04
I have a string like this: firstname;picturefile;info;size

and i need a function that does somthing like
 Function(S : String; Index : Byte) : String;

and if i say index 1 it returns string 'picturefile';

Mvh.
Michael.
0
Comment
Question by:brainware
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 50 total points
ID: 1338289
Hi brainware,

I have this function:

Function Piece(Rec : String; D : Char; I : Integer) : String;
Var
   count,Position,EndPosition : integer;
   stop : boolean;
Begin
   count := 1;
   stop := (count>=I);
   While not stop do begin
       Position := Pos(D, Rec);
       If Position>0 Then
          System.Delete(Rec,1,Position)
       Else begin
          Rec := '';
          stop := true;
       end;
       count := count + 1;
       if count=I then stop := true;
   end;
   EndPosition := Pos(D, Rec);
   If EndPosition = 0 Then
       EndPosition := Length(Rec)
   Else begin
       EndPosition := EndPosition - 1;
   end;
   Piece := Copy(Rec,1,EndPosition);
end;

Please, notice that it's not zero-based but one-based and it is more generic allowing the usage of others separators.
To have the result you asked for, the code is:

Edit1.Text := Piece('firstname;picturefile;info;size'; ';' , 2)

The result is 'picturefile'

IHTH

P.S.: If you have problems with cut & paste, place a comment with your e-mail, so I can send you the code.
0
 
LVL 2

Author Comment

by:brainware
ID: 1338290
Very Fine work.. Thanks ALOT.. and another Thanks for the fast response..
0
 
LVL 4

Expert Comment

by:itamar
ID: 1338291
Your wellcome.

Just a hint: when grading answers, show your happiness giving an "A"

bye,
Itamar
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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