-1

why is the text directly copied from a variable and its length is immediatly less?

Note:This happens inside a xulrunner application. (probably the same would happen in firefox)

var data = NetUtil.readInputStreamToString(inputStream, inputStream.available(),{charset:"UTF-8"});
dump(data.length); //1050
document.body.innerHTML = data;
dump(document.body.innerHTML.length); //1027
if (data!=tempbody.innerHTML) dump("Content has been edited"); //wrong

/*
data:
first
second...
*/

When I print every character in both strings some match to nothing, extract:

for(var i=0;i<data.length;i++) dump(data[i]+":"+tempbody.innerHTML[i]+".");
/*Output:
:f:f.i:i.r:r.s:s.t:t.
.
:
:s.
:e.s:c.e:o.c:n.o:d....
*/

I tried to remove \r and \n in data but only has 2 characters less 1050->1048

data = data.replace('\r','').replace('\n','');
for(var i=0;i<data.length;i++) dump(data[i]+":"+tempbody.innerHTML[i]+".");
/*Output
:f:f.i:i.r:r.s:s.t:t.
.
:s.s:e.e:c.c:o.o:n.n:d.d:...
*/
shuji
  • 7,369
  • 7
  • 34
  • 49

1 Answers1

1

I dont know why I was thinking that replace without adding a regular expression would actually replace every character in the text:

data = data.replace(/\r/g,'');

(I just changed the search to a global regex) Now the length matches.

shuji
  • 7,369
  • 7
  • 34
  • 49