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
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
On Aug 26, 2010, at 12:35 PM, Oscar L. wrote:
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
“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”’ instead:
zz[0] == ‘“s”’
true
On Thu, Aug 26, 2010 at 2:35 PM, Oscar L.
[email protected]wrote:
Regards
OscarPosted via http://www.ruby-forum.com/.
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”
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””
Thanks for all of you!!!
Regards
Oscar
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs