0

I am writing some data to a file. I first generate a string with the following code:

for(var t of transactions){
        outputString += t.playerID + '|' + t.equipmentID + '|' + t.transaction + '|' + this.datePipe.transform(t.transactionTime, 'MM/dd/yyyy hh:ss a') + '|\n';
    }

And then I write to the file:

this.writeFileHelper('HHTransactions.txt', outputString);
....
public writeFileHelper(fileName: string, outputString: string) {
    this.file.writeFile(this.baseDir + '/mobile', fileName, outputString, true).then((Result) => {
        console.log(Result);
    }, (error) => {
        console.log(error)
    });
}

When I read the file on my mobile device, the output data shows data on separate lines, which I would expect \n to do. However, when the file is read by a PC, I end up with all the data in the same line.

Does anyone know why I am seeing this issue? I realize I can use:

writeFile(path, fileName, text, {append: true, replace: false})

But that seems silly to make a call for each record I'm writing into the file.

Thanks in advance.

sparkyShorts
  • 630
  • 9
  • 28

1 Answers1

0

Found out that I needed to add an \r\n for it to do do a carriage return. Obscure piece of knowledge, but hope it helps someone!

sparkyShorts
  • 630
  • 9
  • 28
  • It is the difference between_carriage return_ (`\r`) and _new line_ (`\n`). See [this post](https://stackoverflow.com/questions/15433188/r-n-r-n-what-is-the-difference-between-them) for details. – ttben Nov 27 '18 at 18:41