question about reading and writing to text files

The_Beatle
The_Beatle used Ask the Experts™
on
Hi experts,

i'm actually busy with reading and writing to text files (eol, eofn stuff)
i understand every what writing to a text file is concerned
but reading is my problem

If for example i have got a text file (NAMES.TXT)
with names and phone numbers with this format

Charlotte 0475286589
Yannick    7548635492
Louis       7856342885
Denise     2315648789


how do i do to read just the phone number
because if I do a
Character-read I get this "C"
STRING[15] -read I get this "Charlotte 04752"
STRING -read I get the whole thing

i just want to read the phone number

thanks a lot
the-beatle
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Just read the whole string and copy the part you need (?):

ReadLn(F,S);  {F = textfile, S = string}
PHNr := Copy(S,11,10);  {PHNr = string for phone number}
Quid, Me Anxius Sum?  Illegitimi non carborundum.
Commented:
Do this

var
  p : integer;
  s, r : string;

Readln(F, S);    { get the whole string }
p := pos(' ', S);  { that's a space between the ' ' }
inc(p);
r := copy(s, p, length(s) - p));
writeln(r);

That should do it.
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.

Commented:
Correction.

Follow MRT-RSI comments.  I was presuming you had one space between the name and the telephone number.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Assuming the example is accurate for the file

Var
   Name : String[10];
   Id : String[10];

Begin
....

  readln (f, Name, Id);

....

mlmcc

Author

Commented:
hi

but isn't there just a way to "skip"
the name and the space before the phone number ???

the_beatle
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Not in a text file.  You must read the entire file.  You don't have to do anything with Name but you must read the characters.

mlmcc
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.

Commented:
Try

var
  A, B :  string;

Read(F, A);
Readln(F, B);

The telephone number will be in B.
Commented:
mlmcc wrote "Not in a text file" => if you open the file as a binary file you can use Seek to move through the file, but then remember that there are two extra chars at the end of every 'line': CR (carriage return) and LF (line feed). For ease of use, sticking to text file is better, if it speed you want, switch to a binary file structure.
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
You're right MrT but why complicate matters.

Author

Commented:
yes why complicate it ...
okay with that i understand it more or less but

thanks a lot to everyone

the_beatle

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial