Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

String Parsing...

Posted on 1998-08-31
3
Medium Priority
?
138 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 150 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

877 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