Message from discussion
string encoding
Received: by 10.59.5.166 with SMTP id cn6mr2281228ved.3.1343913354497;
Thu, 02 Aug 2012 06:15:54 -0700 (PDT)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.220.221.197 with SMTP id id5ls2043024vcb.5.gmail; Thu, 02 Aug
2012 06:15:35 -0700 (PDT)
Received: by 10.52.66.44 with SMTP id c12mr2483538vdt.19.1343913335331;
Thu, 02 Aug 2012 06:15:35 -0700 (PDT)
Date: Thu, 2 Aug 2012 06:15:35 -0700 (PDT)
From: Danil Gazizov <danil.gazi...@gmail.com>
To: nodejs@googlegroups.com
Message-Id: <c38a1a97-b1e2-4e8a-98a6-c8782aab1474@googlegroups.com>
Subject: string encoding
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_152_18993808.1343913335050"
------=_Part_152_18993808.1343913335050
Content-Type: multipart/alternative;
boundary="----=_Part_153_25624840.1343913335050"
------=_Part_153_25624840.1343913335050
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
I'm confused of how to compare string const with variable.
Look at this simple example where keyboard input compares with const string.
I suggest this is encoding problem. Please, tell me what should be done to
exit process ?
File encoding is utf8
process.stdin.setEncoding();//default is utf-8
process.stdin.resume();
process.stdin.on("data", function(text) {
//shows entered length=*6*
console.log('entered length=' + text.length);
//shows compare length=*4*
console.log('compare length=' + 'exit'.length);
if (text == 'exit'){
//never works
console.log('matched!');
}
});
------=_Part_153_25624840.1343913335050
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<div><div>I'm confused of how to compare string const with variable.<br>Loo=
k at this simple example where keyboard input compares with const string.<b=
r>I suggest this is encoding problem. Please, tell me what should be done t=
o exit process ?<br>File encoding is utf8</div><div><br><span class=3D"Appl=
e-tab-span" style=3D"white-space: pre; ">=09</span>process.stdin.setEncodin=
g();//default is utf-8</div><div><span class=3D"Apple-tab-span" style=3D"wh=
ite-space:pre">=09</span>process.stdin.resume();</div><div><span class=3D"A=
pple-tab-span" style=3D"white-space: pre; ">=09</span>process.stdin.on("dat=
a", function(text) {<br></div><div>  =
; <br><span class=3D"Apple-tab-span" style=3D"white-space: pr=
e; ">=09</span><span class=3D"Apple-tab-span" style=3D"white-space: pre; ">=
=09</span>//shows entered length=3D<font color=3D"#ff0000"><b>6</b></font><=
/div><div><span class=3D"Apple-tab-span" style=3D"white-space: pre; ">=09=
=09</span>console.log('entered length=3D' + text.length); </div><div><=
br></div><div><span class=3D"Apple-tab-span" style=3D"white-space: pre; ">=
=09=09</span>//shows compare length=3D<b><font color=3D"#ff0000">4</font></=
b></div><div><span class=3D"Apple-tab-span" style=3D"white-space: pre; ">=
=09=09</span>console.log('compare length=3D' + 'exit'.length);<br></div><di=
v><br></div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">=
=09=09</span>if (text =3D=3D 'exit'){<br><span class=3D"Apple-tab-span" sty=
le=3D"white-space: pre; ">=09=09=09</span> //never works<br></div><div=
><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>c=
onsole.log('matched!');</div><div><span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre">=09=09</span>}</div><div><span class=3D"Apple-tab-span" sty=
le=3D"white-space:pre">=09</span>});</div></div><div><br></div>
------=_Part_153_25624840.1343913335050--
------=_Part_152_18993808.1343913335050--