0

I have a QR code scan result, i would like to get a specific string from the result.

example: if the result is "ROGS,Hudson,J'kobi,Anderson,Harrison,454242,SAM,HARRY, TIM, JOHN,SAMMY,TONNY,SAMON,GROOD,TOD."

And i would like to get the name TONNY from the result string. What is the best way to go about this in Android Java code.

My Current code is as below

public void handleResult(Result rawResult) {
        // Do something with the result here

        Log.e("handler", rawResult.getText()); // Prints scan results
        Log.e("handler", rawResult.getBarcodeFormat().toString()); // Prints the scan format
AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Scan Result");
        builder.setMessage(rawResult.getText());
        AlertDialog alert1 = builder.create();
        alert1.show();

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
}
Eaby Babu
  • 21
  • 1
  • 6

1 Answers1

0

Can't you do a simple string match to check for TONNY or any other name?

String required = "TONNY";
String result = rawResult.getBarcodeFormat().toString();
return result.matches(required)

Edit : to ignore case

result.toLowerCase().contains(required.toLowerCase()) 

Check this

Edit2 :To get the no., split the result and loop

String array[] = result.split(",")
for(int i=0;i<array.length;i++)
   if(array[i].equals(required))
     return i
Community
  • 1
  • 1
sandy
  • 509
  • 1
  • 6
  • 23