samedi 19 septembre 2015

issue using charAt. not working in if condition in android

why sb.charAt() not working in if condition. and even if by using some other means i get IF condition working, once it encounters empty space, it starts deleting 2 characters

    StringBuffer sb = new StringBuffer(txt.getText().toString());
                //char[] txt_char_arr =         txt.getText().toString().toCharArray();
                int pos = sb.toString().length() - 1;

                if(sb.charAt(pos)==' ')
                {
                    sb.delete(pos-2, pos);
                    txt.setText(sb);
                }
                else
                {
                    sb.deleteCharAt(pos);
                    txt.setText(sb);
                }

Aucun commentaire:

Enregistrer un commentaire