help if else

T

Tonyrrr Tonyroor

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


????
 
J

Jano Svitok

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 \
 
B

Ben Bleything

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
 
B

Bertram Scharpf

Hi,

Am Freitag, 27. Jul 2007, 00:21:31 +0900 schrieb Ben Bleything:
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.

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"/'

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
 
B

Ben Bleything

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
 

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,264
Messages
2,571,314
Members
47,992
Latest member
JavierBini

Latest Threads

Top