Solved

String Parsing...

Posted on 1998-08-31
3
124 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

22 Experts available now in Live!

Get 1:1 Help Now