jeudi 28 janvier 2016

why doesn't my character comparison work?

Hi stackoverflow community,

I was working on an android app in which I have to disassemble a string. First I want to check if the first character of that specific string is this one: §. I already have used such an if clause before in the same project, where it works fine. I have already done research on this topic and I found out that it is possible to compare chars the way i do in java. I have also rebuilt the project a couple of times, as I am going mad right now. Thanks for your support.

Here is the code where I create the headingString:

SharedPreferences prefs = this.getSharedPreferences(
            "com.myapp.app", Context.MODE_PRIVATE);
    String headingString=prefs.getString("directions", getResources().getString(R.string.heading_default));
    if (headingString.length()==0) {
        headingString=getResources().getString(R.string.heading_default);
    }

Here is my problematic java code:

Log.i("HeadingActivity", "headingString.charAt(0)==" +headingString.charAt(0));
if (headingString.charAt(0)=='§') {
Log.i("HeadingActivity", "success!");
// other code
}

My log only says:

I/HeadingActivity﹕ headingString.charAt(0)==§

Thanks for your effort again, I really appreciate it. I apologise for all the mistakes I may have made creating that post or concerning my java code.

Aucun commentaire:

Enregistrer un commentaire