writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

BoQsc vaidas.boqsc at gmail.com
Wed Jun 3 19:53:03 UTC 2020


> Removing the last element of the string got it resolved.
> Might not be the best way and adding additional check for 
> carriage return before removing the element would be better, so 
> this is only initial proof.


Improved example with the above comments resolved.

testingGround.d
> import std.stdio;
> import std.algorithm;
> 
> 
> 
> int lineNumber;
> void main(){
> 
> 	File exampleFile = File("exampleText.txt");
> 	lineNumber = 0;
> 	foreach(line; exampleFile.byLine){
> 		
> 		if (line == " Sphinx of black quartz, judge my vow.\u000D"){
> 			if (line[line.length -1] == '\u000D'){
> 				line = line.remove(line.length - 1);
> 			}
> 			writeln(lineNumber, ". hahahahahahaha", line, " nononono");
> 			
> 		} else {
> 			writeln( lineNumber, ". ", line[line.length -1]);
> 		}
> 		
> 		lineNumber++;
> 	}
> }


More information about the Digitalmars-d-learn mailing list