I have just come across something I've not seen before, when I INPUT# from a file the resulting string has a square/box symbol as the first character and when using LEN to calculate the length of the string I get the result 5 if the rest of the string is "x" making the square/box symbol 4 characters long.
Can anyone offer any suggestions.
Box symbol
-
- Posts: 208
- Joined: Tue 17 Apr 2018, 21:03
Box symbol
Kind Regards Ric.
6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
-
- Posts: 39
- Joined: Thu 05 Apr 2018, 14:08
Re: Box symbol
You will only get from INPUT# from a file something you've PRINT#'d to it (or manually contructed with BPUT), unless you have misaligned PTR.Ric wrote: ↑Thu 24 Apr 2025, 09:30 I have just come across something I've not seen before, when I INPUT# from a file the resulting string has a square/box symbol as the first character and when using LEN to calculate the length of the string I get the result 5 if the rest of the string is "x" making the square/box symbol 4 characters long.
Can anyone offer any suggestions.
What does this give you:
FOR a=1 TO LEN yourstring$:PRINT ASC MID$(yourstring$,a,1):NEXT
...where yourstring$ is the string you've INPUT#'d.
-
- Posts: 366
- Joined: Tue 18 Jun 2024, 09:32
Re: Box symbol
Just to back up Jonathan's comment, INPUT# is for reading a file written with PRINT# (using the same version of BBC BASIC) - if the file you are reading was written by some other program all bets are off, and indeed the results will differ depending on the version of BBC BASIC you are using.
To read such a 'foreign' file use GET$# (or indeed BGET# if that's more suitable), not INPUT#; GET$# will work in a consistent way across all versions of BBC BASIC.
You mean bytes, not characters. A UTF-8 character can be one, two, three or four bytes long (although if limited to the Basic Multilingual Plane the maximum is three bytes).making the square/box symbol 4 characters long.
-
- Posts: 208
- Joined: Tue 17 Apr 2018, 21:03
Re: Box symbol
Thanks for replying guys, the confusing part was that only one piece of data was affected, so I thought. (Number 13256 in a list off 141677 that is), but after some investigation the last one was also affected. However, as all the strings PRINT#ed were the same length of 4, when INPUT#ed they appeared to be correct, but obviously had been shifted. The problem was a missing % sign
.
When I tried Jonathan's for/next loop the offending data read many blank characters and then the correct string.
Ps I believe the box symbol to be CHR$(128)
When I tried Jonathan's for/next loop the offending data read many blank characters and then the correct string.
Ps I believe the box symbol to be CHR$(128)
Kind Regards Ric.
6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
-
- Posts: 366
- Joined: Tue 18 Jun 2024, 09:32
Re: Box symbol
You say that you were writing (and reading) strings, so there should be a $ sign. A % signifies a number (in fact an integer) but definitely not a string!
Many other dialects of BASIC automatically convert numbers to strings when written to a data file; unusually (but for a good reason) BBC BASIC doesn't and to create a 'compatible' data file you must use an explicit STR$.
The section of the Help documentation on Compatible data files goes into more detail, but this was written literally decades ago (by Doug Mounter) and really could do with updating!