Page 1 of 1

Need to get this done quickly for a relative

Posted: Sun Jan 30, 2005 2:38 am
by Queth
Hi,

I have this problem - well actually a relative has this problem. They have lost some text from a file, and I found it in a tempory file. The trouble is, there is heaps of text, and there are extra spaces (hard to explain) -

eg: T h i s i s t(1 space)h(1 space)e(2 spaces)t(1 space)e x t .

So I've been going through it, deleting one space, moving ahead, deleting one space .... but this will take AGES.

I have a few ideas, but I would like to hear your ideas on how I would go about writting a program to do this. It has to be able read from a file, and then take out the extra spaces and save the result. (It's the middle part I don't know how to do.)

Thanks for your help,
Quentin McKenzie.

Posted: Sun Jan 30, 2005 9:22 pm
by Ralph
Here is a partial solution, which will reduce the problem to a much smaller one. It consists of taking out ALL spaces, then going back in and adding the spaces between each word. Here's how:

Open Notepad, Workpad, Word, or any such. Now, open the text file from within that program. Click on Edit, Replace, enter a blank space in the "Find what" window, and just click "Reblace all". Your text file will now be empty of all spaces.

If you wish, you can enter the one (or two?) spaces after each period, by using the above Replace method, using a simple period in the "Find what", and a period and a space (or two) in the "Replace with", and pressing "Replace all"

Now, you have to go to the end of each word and press the space bar.

Still quit a large job, but reduced quite a bit!

Let us know just how you solved your problem! And, good luck! :D

Posted: Sun Jan 30, 2005 9:39 pm
by Guest
I didn't think of that way. In fact, I didn't even know you could do that (I've had no call to do it in the past.)

I haven't solved the problem yet (ie: I haven't done anything more). I'll do that, and let you know how I go.

Thanks,
Quentin.

PS: You seem unsure - it was one extra space. Between the words, there is already a space, so an extra space makes two spaces. Hope this clears it up.

Posted: Sun Jan 30, 2005 11:31 pm
by Queth
Guess who the guest was.

Anyway - I've cracked it. :-D For those who may be interested, I'll post the code here. (although I'm sure this is very simple).

Code: Select all

INPUT "FILE TO BE DE-SPACED..."; F$
OPEN F$ FOR INPUT AS 1
LINE INPUT #1, A$
CLOSE #1
DIM W$(LEN(A$))
PRINT "file size: "; LEN(A$); " characters.": PRINT ""
FOR C = 1 TO LEN(A$)
IF MID$(A$, C, 1) <> " " THEN W$(C) = MID$(A$, C, 1)
IF C <> 1 AND MID$(A$, C, 1) = " " AND W$(C - 1) <> "▓" THEN W$(C) = "▓"
IF C <> 1 AND MID$(A$, C, 1) = " " AND W$(C - 1) = "▓" THEN W$(C) = " "
IF C = 1 THEN W$ = MID$(A$, C, 1)
NEXT
FOR C = 1 TO LEN(A$)
IF W$(C) = "▓" THEN W$(C) = ""
NEXT
FOR C = 1 TO LEN(A$)
PRINT W$(C);
NEXT
PRINT "": PRINT ""
PRINT "File size: "; LEN(A$); " characters."
OPEN F$ FOR OUTPUT AS 1
FOR C = 1 TO LEN(A$)
PRINT #1, W$(C);
NEXT
CLOSE #1
PRINT "Output saved to "; F$
END
There's probably a more direct way to do this - but this'll do.

Q

Posted: Tue Feb 01, 2005 12:20 am
by buff1
When Qbasic or Quick basic Bsaves a "text" file i.e. mode 0, it will have the
text as T h i s t h e t e x t.

This is because 1 byte is the background and foreground colors and 1 byte
is the actual text. That is what is sounds like to me.