Solved

String Parsing...

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 156
delphi popmenu non latine charcters 3 49
Using MMsystem To change audio input 1 40
QuickReport, Delphi, Shape 12 49
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…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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