Jump to content
Macro Express Forums

Changing text file


Recommended Posts

I regularly play my son at Scrabble, online. He's championship standard so I have permission to cheat to avoid boring him. One tool I use is an anagram maker that (after some simple manual editing) gives me a sorted list like this in any text editor:

 

Ahoy
Ale
Ale
Aloe
Aloe
Aloe
Alto
Ate
Auto
(etc)

 

I want a macro to eliminate all repetitions, giving this:

 

Ahoy
Ale
Aloe
Alto
Ate
Auto
(etc)

 

I could of course do this with the working file open in my text editor. Which also appeals because it avoids even having to save the file. After all, I'm just pasting and sorting to view the words temporarily. Nevertheless I'd prefer the 'elegance' of using Text File Process instead. So I saved the document as Anagram.txt and compared each line to the previous, deleting it if identical. All easy stuff.

 

But I have a mental block on how to re-display the file after the deletions! How do you edit the file itself as you step through each line? I'm thinking I'd probably be better off with the obvious, cruder method.

 

With time zones in mind I'll probably solve this myself later today. But just in case anyone's around to give me a heads up please ... while I concentrate on my next move! :)

 

--
Terry, East Grinstead, UK

Link to comment
Share on other sites

Sorted thanks.

 

It proved easy to get the result I wanted with a macro working in the text editor itself.

 

I then discovered the way (well, one way) to do it using the neater and faster Text File Process method. I built a file from each line (after deleting duplicates), complete with CRLFs, and then finally saved that, replacing the original.

 

--
Terry, East Grinstead, UK

Link to comment
Share on other sites

I would read the file in as a string and split it into an array. Do my thing there by looping through the array. Then I would join it on CRLF and save that string to a file.

 

BTW there are Scrabble cheat apps out there for your smartphone. Just enter all your tiles.

Link to comment
Share on other sites

Thanks Cory.

 

Haven't done much with arrays but I'll experiment.

 

I hit a couple of snags with the macro I mentioned. Turned out it failed with more than two identical successive words. And sprinkled the result with empty lines. Obviously written too impatiently!

 

I'll have a look for those apps, although that might take the cheating over acceptable limits!

Link to comment
Share on other sites

Once Anagram.txt is saved, read it and write Anagram_2.txt.

Delete lines by NOT writing them to Anagram_2.txt.

When Anagram_2.txt is complete, display it by calling Notepad with Anagram_2.txt as the parameter.

 

Not fancy or especially elegant, but simple and should be plenty fast enough so your son won't fall asleep.

Link to comment
Share on other sites

Thanks Bob. That approach worked fine, although I didn't need to use a second file. I TextTyped the de-duplicated version, built with Text File Process, over the original.

 

Meanwhile, following up Cory's suggestion, I today found a cheat program that makes the macro entirely redundant!

 

--
Terry, East Grinstead, UK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...