May I know that why the zz[0]=="s" return false, please?

O

Oscar Lok

Dear Sir,

May I know that why the zz[0]=="s" return false, please?

aa = '"s";"d";"f"'
zz = aa.split(";")
zz[0]=="s"
false

Thanks

Regards
Oscar
 
G

Gennady Bystritsky

Dear Sir,
=20
May I know that why the zz[0]=3D=3D"s" return false, please?
=20
aa =3D '"s";"d";"f"'
zz =3D aa.split(";")
zz[0]=3D=3D"s"
false

"s" is a string containing one actual character (s). While you have 3 after=
split -- double quote, s, double quote. So you need to check for '"s"' ins=
tead:

zz[0] =3D=3D '"s"'
true
 
A

Alex Stahl

Because it is.

The original string which you split on results in "s" being assigned to
zz[0], including the quotes. (i.e. you're assigning three characters to
each array element).

When you compare for equality on the next line, due to syntax you're
only comparing to one character - s - as the quotes indicate to ruby
that it's dealing w/ a string literal.

Try this:
zz[0] == "\"s\""
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

Dear Sir,

May I know that why the zz[0]=="s" return false, please?

aa = '"s";"d";"f"'
zz = aa.split(";")
zz[0]=="s"
false

Thanks

Regards
Oscar
You output an inspected view of your objects with the method p, that should
help you see the difference.

aa = '"s";"d";"f"'
zz = aa.split(";")
p zz[0]
p "s"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top