problem with String.indexOf()

This is driving me mad and i cannot figure out where the problem is…

Example code:

String _str = “1234”;

if(tmpStr.indexOf(“1234”) >= 0 ){} ----> FALSE
if(tmpStr.indexOf(String(“1234”)) >= 0 ){} ----> FALSE

However:
boolean okStr =tmpStr.indexOf(“1234”) >= 0;
if(okStr)){} —> TRUE

Strange this is that debugPrinting gives:

SerialPrint( “A=” + tmpStr.indexOf(“1234”));
SerialPrint( “B=” + tmpStr.indexOf(“1234”) >= 0);

SerialPrint( “C=” + tmpStr.indexOf(“34”));
SerialPrint( “D=” + tmpStr.indexOf(“34”) >= 0);

A=0 (correct)
B=1 (=true) (correct)
C=2 (correct)
D=1 (=true) (correct)

Typecast problem perhaps?
indexOf() is supposed to return an signed int, hence if(0>=0) should evaluate to true,

i have a similiar problem with a char instead of String
String str= “0135”;
byte i=3;

int _index = str.indexOf((char)i); => should return 2, since nr 3 is in position nr 2 of str
if(_index>=0) → FALSE (incorrect).

Any ideas?

Any ideas?

How about posting some code that compiles and shows the problem ?

  SerialPrint( "A=" + tmpStr.indexOf("1234"));

SerialPrint - wrong
tmpStr.indexOf - tmpStr not declared
You seem to be trying to concatenate a text constant with an integer and all of this inside a print statement. Does that work ?

UKHeliBob:

Any ideas?

How about posting some code that compiles and shows the problem ?

  SerialPrint( "A=" + tmpStr.indexOf("1234"));

SerialPrint - wrong
tmpStr.indexOf - tmpStr not declared
You seem to be trying to concatenate a text constant with an integer and all of this inside a print statement. Does that work ?

I know about the Serial.print(... that doesnt even compile, i just wrote it to show what i've done, in a semi-pseudo code.

After further investigations, i found out that the problem is not in indexOf().
The problem was with my if-statement