dimanche 28 juin 2015

android Strings and if statement

Im sure this is really simple but it bugging the hell out of me

I use the following code

    String name = Global.PicName2;
    String tempstr = name.substring(0, 3).trim();
    Toast.makeText(getBaseContext(), tempstr, Toast.LENGTH_LONG).show();


    if (tempstr == "Sou"){Toast.makeText(getBaseContext(), "Yes", Toast.LENGTH_LONG).show();}

Now the first Toast reports that tempstr is "Sou" I have checked the lenght of the string and it is 3 characters long I have trimmed any spaces

Yet it will not go through the if statement and toast yes

If I add the line

    tempstr="Sou";

after the first toast it goes through the if statement so that says its the tempstr that is wrong but I cant work out why

Its driving me nuts any ideas?

Any help appreciated

Mark

Aucun commentaire:

Enregistrer un commentaire