Solved

String Parsing...

Posted on 1998-08-31
3
133 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
[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
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

632 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