D Snippet: Reading a file to standard output on Windows Operating System. (FileScan.d)

BoQsc vaidas.boqsc at gmail.com
Wed Dec 6 14:56:50 UTC 2023


As of recent observation the `line` in the previous 
implementation seem to recognise **\r** as default terminator. 
Making `writeln("|" ~ line ~ "|");` not possible.

By correcting terminator and disabling it on `byLine` function it 
is possible to achieve following output to standard stream:

**Output**
```
|test|
| s|
| |
|   HelloWorld|
^This Line is here.
|t|
|ff|
```

**Input (example.txt)**
```
test
  s

    HelloWorld
t
ff
```

**Source code**
```
import std;

void main(){

	foreach (line; File("example.txt").byLine(No.keepTerminator, 
"\r\n")){
		writeln("|"~line~"|");
		if (line == "   HelloWorld") { writeln("^This Line is here."); }
	}

}
```



More information about the Digitalmars-d-learn mailing list