Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 18, 2017 D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText() | ||||
---|---|---|---|---|
| ||||
DMD32 D Compiler v2.074.1 import std.file; void main() { string bigInput = readText("input.txt"); } The file is 7 MB of ascii text, don't know if that matters... Should I upgrade versions? |
July 18, 2017 Re: D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Enjoys Math | On Tuesday, 18 July 2017 at 02:21:59 UTC, Enjoys Math wrote:
>
> DMD32 D Compiler v2.074.1
>
> import std.file;
>
> void main() {
> string bigInput = readText("input.txt");
> }
>
> The file is 7 MB of ascii text, don't know if that matters...
>
> Should I upgrade versions?
I wonder if it thinks there is a BOM and eats it?
|
July 19, 2017 Re: D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Enjoys Math | On Tuesday, 18 July 2017 at 02:21:59 UTC, Enjoys Math wrote:
>
> DMD32 D Compiler v2.074.1
>
> import std.file;
>
> void main() {
> string bigInput = readText("input.txt");
> }
>
> The file is 7 MB of ascii text, don't know if that matters...
>
> Should I upgrade versions?
Could you please share the first 32-bytes (in hex) of your file? Like:
$ hexdump -C input.txt
|
July 19, 2017 Re: D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Enjoys Math | On 7/17/17 10:21 PM, Enjoys Math wrote:
>
> DMD32 D Compiler v2.074.1
>
> import std.file;
>
> void main() {
> string bigInput = readText("input.txt");
> }
>
> The file is 7 MB of ascii text, don't know if that matters...
>
> Should I upgrade versions?
Looking at the implementation of readText, I believe its implementation is not able to trim off the beginning of a file. Be wary of how you look at the result, some tools may "helpfully" hide things (like unprintable characters, or overwrite what has already been displayed when it sees a carriage return).
If you can't figure it out yourself, the best thing to do here is to post your exact file somewhere so people can diagnose. Or reproduce with a smaller one, and then post that somewhere.
-Steve
|
July 20, 2017 Re: D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Wednesday, 19 July 2017 at 15:18:00 UTC, Steven Schveighoffer wrote:
> On 7/17/17 10:21 PM, Enjoys Math wrote:
>>
>> DMD32 D Compiler v2.074.1
>>
>> import std.file;
>>
>> void main() {
>> string bigInput = readText("input.txt");
>> }
>>
>> The file is 7 MB of ascii text, don't know if that matters...
>>
>> Should I upgrade versions?
>
> Looking at the implementation of readText, I believe its implementation is not able to trim off the beginning of a file. Be wary of how you look at the result, some tools may "helpfully" hide things (like unprintable characters, or overwrite what has already been displayed when it sees a carriage return).
>
> If you can't figure it out yourself, the best thing to do here is to post your exact file somewhere so people can diagnose. Or reproduce with a smaller one, and then post that somewhere.
>
> -Steve
I'm feeling this. My keyboard sometimes messes up and will send invalid key presses to my OS which often ends up with invalid characters being written in files.
When I encounter it I usually open Notepad++ and turn on show all characters which will display unprintable characters, simply allowing me to delete them and have a clean file again.
|
Copyright © 1999-2021 by the D Language Foundation