Hello
I have a delimiterless text file consisting of a long (~1000 chrs) set of ASCII characters (ABCDEFGHIJK ....) and I would like to read in and process each character individually. Can anyone help me with an easy way to do this, please?
Many thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Rob. Many thanks for your speedy response. I must confess that I had wondered about your first way, but discarded it because of the documentation entry about INPUT$ :
Returns a string of num_chars characters from the keyboard or, if file_num is provided, from a text file.
Parameters
• num_chars is a numeric expression in [1—255].
My reason for discarding the first way was that I reasoned that when I = 1000, line 30 tries to read
num_chars (1000) into A$ , which is prohibited by the parameter definition. Have I missed something here?
Thanks for the second process.
Sincerely
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You're right, I made a typo in the first bit of code: num_chars should be 1, not I: Each time, one character is read. The limitation is that you can read at most 255 characters at a time, but more won't fit in a string anyway.
I've corrected the code above.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "[CLOSED] General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hello
I have a delimiterless text file consisting of a long (~1000 chrs) set of ASCII characters (ABCDEFGHIJK ....) and I would like to read in and process each character individually. Can anyone help me with an easy way to do this, please?
Many thanks
The easiest way: if you need to read the characters in order, you could use
INPUT$
to read single characters from a text file, something like:If you're going to have to jump around in the file, you could open as a random-access file with one-byte record length, e.g.:
Last edit: Rob Hagemans 2016-12-05
View and moderate all "[CLOSED] General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hello Rob. Many thanks for your speedy response. I must confess that I had wondered about your first way, but discarded it because of the documentation entry about INPUT$ :
INPUT$
chars = INPUT[ ]$ (num_chars [, [#] file_num])
Returns a string of num_chars characters from the keyboard or, if file_num is provided, from a text file.
Parameters
• num_chars is a numeric expression in [1—255].
My reason for discarding the first way was that I reasoned that when I = 1000, line 30 tries to read
num_chars (1000) into A$ , which is prohibited by the parameter definition. Have I missed something here?
Thanks for the second process.
Sincerely
You're right, I made a typo in the first bit of code:
num_chars
should be1
, notI
: Each time, one character is read. The limitation is that you can read at most 255 characters at a time, but more won't fit in a string anyway.I've corrected the code above.