Forum: Ruby help if else

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
25e8ef7debb2f323181a4cbbafc068a1?d=identicon&s=25 Tonyrrr Tonyroor (r0nsync)
on 2007-07-26 16:55
   if ((( chaine[i+14] == "twincards>false</twincards")||(chaine[i+14]
== "twincards>true</twincards"))|| ( chaine[ i+14]== "twincards
xsi:nil="1"/"))


???

  : syntax error, expecting      end-of-file


????
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-07-26 17:09
(Received via mailing list)
On 7/26/07, Tonyrrr Tonyroor <r0nsync@yahoo.fr> wrote:
>    if ((( chaine[i+14] == "twincards>false</twincards")||(chaine[i+14]
> == "twincards>true</twincards"))|| ( chaine[ i+14]== "twincards
- xsi:nil="1"/"))
+ xsi:nil=\"1\"/"))

you have to escape quotes with \
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2007-07-26 17:23
(Received via mailing list)
On Thu, Jul 26, 2007, Tonyrrr Tonyroor wrote:
>    if ((( chaine[i+14] == "twincards>false</twincards")||(chaine[i+14]
> == "twincards>true</twincards"))|| ( chaine[ i+14]== "twincards
> xsi:nil="1"/"))

You're closing one too many sets of parents after the "true"
conditional.  Also, in the third conditional, you need to either escape
the inner quotes or use single quotes:

  "twincards xsi:nil=\"1\"/"
  'twincards xsi:nil="1"/'

You might want to rewrite it for better legibility, too.  A suggestion:

  test = chaine[ i + 14 ]
  if test == 'twincards>false</twincards' or
     test == 'twincards>true</twincards'  or
     test == 'twincards xsi:nil="1"/'

     # do whatever
  end

Ben
C06869c119472a139eb163b72040b0db?d=identicon&s=25 Bertram Scharpf (Guest)
on 2007-07-26 17:35
(Received via mailing list)
Hi,

Am Freitag, 27. Jul 2007, 00:21:31 +0900 schrieb Ben Bleything:
>   test = chaine[ i + 14 ]
>   if test == 'twincards>false</twincards' or
>      test == 'twincards>true</twincards'  or
>      test == 'twincards xsi:nil="1"/'

It's not only legibility, it's enough to calculate c[i+14]
once as the result is every time the same.

Another suggestion:

  case chaine[ i+14]
    when %r{twincards>(true|false)</twincards},
         %q{twincards xsi:nil="1"/}             then
      ...
  end

Bertram
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2007-07-26 17:46
(Received via mailing list)
On Fri, Jul 27, 2007, Bertram Scharpf wrote:
> It's not only legibility, it's enough to calculate c[i+14]
> once as the result is every time the same.

Right!  I forgot to mention that :)

> Another suggestion:
>
>   case chaine[ i+14]
>     when %r{twincards>(true|false)</twincards},
>          %q{twincards xsi:nil="1"/}             then
>       ...
>   end

My gut tells me this might be slower, but probably not enough to matter.
And I always forget about %q, that's really the best way to quote
something that has quotes inside it.

Ben
This topic is locked and can not be replied to.