Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Q - text extraction

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
hello all - I have a text file with information that I need to extract. I don't have any clue prior to receiving the file any of the characters in the line, but I know the position and length of each item I need to collect:
(00040000102021502041508:30A.M CITY/COUNCIL CHAMBERS 1 CIVIC PLAZA RM B2125 000P999304754ABEITA, MARGARET P O BOX 74 ISLETA PUEBLO NM87022 KEVIN L. FITZWATER TOBIAS MARTINEZ)
All the information is on one line in my text file but separated by multiple spaces. I need to extract the name (position 160), the address (position 190, length 25).
What Delphi procedure/function can I use to extract from an known position?

Thanks for any input.

leslie

ps - There will probably be LOTS of questions from me in the next month or so (starting a new project and very little Delphi experience!). Thanks in advance for all the helpful information you Tekkers share! %-)
 
hi,

if you know the position and length you can do the following:

var
F: TextFile;
S: string;
Name, Address : string;
begin
if OpenDialog1.Execute then
begin
AssignFile(F, OpenDialog1.FileName);
Reset(F);
Readln(F, S);
Name := Copy(s, 160,25); // extract name
address := copy(s,190,25); // extract address
CloseFile(F);
end;
end;

Hope this is what you want.

Steph [Bigglasses]
 
Copy

This function returns a part from the string target, with a length of L characters from the

position specified in Index


Target := 'Turbo Pascal Compiler'
L := 6;
Index := 7;

substring := Copy (Target, Index, L );

will results in substring = Pascal

This is a fragment of "How do I search, copy or delete from strings" faq218-360 in the pascal forum.

Regards


Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top