-1

I'm trying to check the string if a sentence has a word "TIN" but it says false when i try to use equal or '=='. Here is my code.

            if (!recognizer.isOperational()) {
                Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
            } else {
                Frame frame = new Frame.Builder().setBitmap(bitmap).build();
                SparseArray<TextBlock> items = recognizer.detect(frame);
                StringBuilder sb = new StringBuilder();
                //get text from sb until there is no text
                for (int it = 0; it < items.size(); it++) {
                    TextBlock myItem = items.valueAt(it);
                    sb.append(myItem.getValue());
                    sb.append("\n");
                    if (myItem.getValue() == ("TIN")) {
                        Toast.makeText(this, "VERIFIED ID", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "WRONG ID", Toast.LENGTH_SHORT).show();
                    }
                }
                //set text to edit text
                mResultEt.setText(sb.toString());
            }

3 Answers3

2

When writing myItem.getValue()==("TIN") you only check if the handles of the two objects are identical. To compare their contents, you must write myItem.getValue().equals("TIN").

Zelig63
  • 1,592
  • 1
  • 23
  • 40
1

I think you want to check if it contains the value "TIN" in string. If you want to check value contain in a string then use below -

if (myItem.getValue().contains ("TIN")) {
    //... code
}
Dipankar Baghel
  • 1,932
  • 2
  • 12
  • 24
1

if a sentence has a word "TIN" means you want to check a particular word in a sentence.

So use, myItem.getValue().toString().contains("TIN")

AbhiN
  • 642
  • 4
  • 18