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!

Something for the weekend #2: Numbering the lines 3

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
My previous weekend brain exercise turned turned out to be too easy - although it did generate an interesting discussion. Let me give you something different to think about this time.

You have a text file. The requirement is simply to add line numbers to it.

For example, the file might look like this:

[tt]Alfreds Futterkiste
Antonio Moreno Taquería
Around the Horn
Berglunds snabbköpö
Blauer See & Delikatessen
Blondel père et fils
Bólido Comidas preparadas
Bon app' edited
Bottom-Dollar Markets[/tt]

Your job is to make it look something like this:

[tt]1 Alfreds Futterkiste
2 Antonio Moreno Taquería
3 Around the Horn
4 Berglunds snabbköpö
5 Blauer See & Delikatessen
6 Blondel père et fils
7 Bólido Comidas preparadas
8 Bon app' edited
9 Bottom-Dollar Markets[/tt]

As before, the aim is to do the job with the least amount of code (fewest lines, shortest lines).

If you are one of the first to reply, please wrap your solution in [ignore][/ignore] tags so that others won't see it straight away.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I hope you all enjoy doing these little exercises.

It's always fun when one of these older commands surprises with a "new" feature that's been hidden in plain sight all these years. [bigsmile]
 
Did you know that ...?

Many people turn off those start messages from any product, because they are bugged by them and want to work and know what they want to do and how.

As I work with C# a lot more now since this year and have got a license of resharper, I didn't turn this products start messages off, even though I often don't have the time to take a closer look at a feature described. They partly are not what I'd want to know right now or ever, but I feel I better get to learn all the features of resharper, if I keep this on.

Especially since this is before you start working, you always have the one to five minutes to goo through one of these tips and see, if it can help you, perhaps not now, but later.

Bye, Olaf.
 
I share the same opinion with Dan. Until now I didn't know about this parameter.
I searched in the help for the type command (after I saw List cannot produce numbers), because VFP has some DOS command, like md or rd.

I tried to overwrite the source file, but VFP complains: the file is in use, and the size becomes 0.
Is there a trick, or maybe in other version of VFP?

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
You're right. I confess, I use List only for testing.
I checked the List command and I saw it can't help me because it can't type the content of a text file (or maybe I don't know how).
Then I searched the help for something else, and I recalled the "Type" Dos command.

Anyway, I agree this kind of threads are fun and instructive.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
I tried to overwrite the source file, but VFP complains: the file is in use, and the size becomes 0.

That's strange. I don't see that problem. Are you sure the file isn't open in another application,such as Microsoft Word?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
LIST... >can't type the content of a text file (or maybe I don't know how).

Indeed, I tried LIST FILES LIKE [Skeleton], but it merely lists filenames and size, etc.
Dan used list on a cursor prepared with appending the input file.

And I also didn't get TYPE to output into the same file it reads.

Bye, Olaf.

 
Are you sure the file isn't open in another application,such as Microsoft Word?

100% sure. Maybe the version of VFP? I use VFP9 SP2 version 9.0.7423
But it's easy to simulate. Delete the source and rename the destination with the source name :)

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Very nice initiative.
A very polite way to show me how little I know :)
I already ask myself what's the next challenge.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top