0

I know there's a lot of posts on this, but the answers are not working for me. Here's a link with good answers - but did not work for me: How to remove all line breaks from a string

and this is how I tried to remove tgh CR LF:

let newdata: string = JSON.stringify(data);
newdata =new String(newdata).valueOf();
// newdata = newdata.replace(/(\r\n|\n|\r)/gm, '');
newdata = newdata.replace(/\r?\n|\r/g, '');

and I will post bothe a screenshot of the string in notepad++ so you can see it, then I will paste the string below if you want to test it.

enter image description here

and this is the string:

[{"type":"-","name":"aaSomeFile - Copy.txt","size":12,"modifyTime":1664204606000,"accessTime":1664981500000,"rights":{"user":"rw","group":"***","other":"***"},"owner":0,"group":0,"longname":"-rw-******    1 -        -
        12 Sep 26 11:03 aaSomeFile - Copy.txt"},{"type":"-","name":"SomeFile.txt","size":12,"modifyTime":1664204606000,"accessTime":1664204606000,"rights":{"user":"rw","group":"***","other":"***"},"owner":0,"group":0,"longname":"-rw-******    1 -        -              12 Sep 26 11:03 SomeFile.txt"},{"type":"-","name":"SomeFile1.txt","size":12,"modifyTime":1664204606000,"accessTime":1666806607000,"rights":{"user":"rw","group":"***","other":"***"},"owner":0,"group":0,"longname":"-rw-******    1 -        -              12 Sep 26 11:03 SomeFile1.txt"},{"type":"d","name":"TestFolder1","size":0,"modifyTime":1667511799000,"accessTime":1667511799000,"rights":{"user":"rwx","group":"***","other":"***"},"owner":0,"group":0,"longname":"drwx******    1 -        -               0 Nov  3 17:43 TestFolder1"},{"type":"-","name":"zzzSomeFile2.txt","size":12,"modifyTime":1664204606000,"accessTime":1666806623000,"rights":{"user":"rw","group":"***","other":"***"},"owner":0,"group":0,"longname":"-rw-******    1 -        -              12 Sep 26 11:03 zzzSomeFile2.txt"}]

Can anyone tell me how this can be removed?

Thank you.

kelsny
  • 23,009
  • 3
  • 19
  • 48
spacedog
  • 446
  • 3
  • 13
  • How are you viewing / verifying that the strings contain CRLF? There's no display code in your question. Are you logging the values or using a debugger? – Phil Nov 04 '22 at 00:55
  • @Phil good question. console.log(newdata ). The above is the output from console.log. I discovered this bucause the carriage return corrupts the json and it won't parse. – spacedog Nov 04 '22 at 01:40
  • JSON can contain literal newlines just fine ~ https://jsfiddle.net/xjfy2hdo/. Perhaps you're trying to solve a problem that doesn't exist – Phil Nov 04 '22 at 01:45

0 Answers0