Click here to LOGIN
Information
Tutorials & Articles
Programs
Feedback
 


Forum
Add a Post
Username:   (You must log on to use your member username)Hint: Use [code] and [/code] around text to highlight it as QB code.


Subject:
Message:
Forums -> Q & A -> How to remove a certain character range...
sintral
How to remove a certain character range from a Random-Access file
Posted Oct 01 2009
I have a random-access file that is 8988121 characters wide. I need to remove characters 7831621 - 8902081. Text editors (Notepad++) can't handle text manipulations well of this magnitude. Anyone know how I can handle this through code? As a tangent, does anyone know how to combine two random-access files by appending one to the end of the other? BTW, NULL characters at the end of each records prevent copy and paste as the text editor considers them a stop point.
Clippy
Does the file consist of fixed length Records?
Posted Oct 01 2009
1) Normally Random files consist of records defined by a TYPE or FIELD definition. The records can hold several different variable types. Did you try reading it in a DOS editor? Just type EDIT filename in DOS or SHELL. Notepad cannot read ASCII correctly.

2) ANY file can be opened FOR RANDOM! But do you actually need that?

3) If the file consists of just Text (strings) do they have spaces at the end of them? This would indicate a fixed length string in a Record.
You can use LINE INPUT in the INPUT mode to see that without hurting the file. If the return holds ASCII characters, then it is probably a number value in a record. The key is finding the record's size! You don't want to remove partial records, but you will have to do some math to figure how many to remove. The ONLY way to remove records is to make a TEMP file and copy the records at the beginning to that file. Once done with the data copy, SHELL Copy in DOS or use NAME to rename the temp file back to the original name.

4) You can add other file data to the end of a Random file by finding the current number of records in the file. You should know that if you created it. But if you forgot. Take the LEN of the TYPE variable or FIELD statement and divide the LOF by the record size.

records = LOF(1)/ LEN(typevariable)

The result cannot be a fraction of records if it is correct! Once you know the record count use add same length records using PUT #1, records + 1, recordtype. Then just use PUT #1, , recordtype as PUT will place the rest consecutively.

The added records MUST be the same size and type order as the old ones or you will be reading the wrong data later!




The QBasic Station, (C) Copyright 1997-2010