Solution 1 :
Use String#contains
:
String bc = barcode.displayValue
if (bc.contains("CZV")) {
bc = "LOKO";
}
barcodeValue.setText(bc);
Solution 2 :
String bc = barcode.displayValue
bc = bc.contains("CZV") ? "LOKO" : bc;
barcodeValue.setText(bc);
Solution 3 :
You can use the contains
function:
String myString = barcode.displayvalue;
if(myString.contains("CZC")){
myString = "replaced";
}
Problem :
If a string of a barcode scan (f.e.) contains “CZC” I want to be able to change the whole string into (f.e.) “LOKO”.
if (data != null) {
Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
statusMessage.setText("Strichcode erfolgreich gelesen");
barcodeValue.setText(barcode.displayValue);
Log.d(TAG, "Strichcode Scannen: " + barcode.displayValue);
This part and more of the code that I have already written is supposed to change the whole string if “CZC” is contained.
Comments
Comment posted by Scalway
Question: You need to detect if string contains substring. If yes set barcode value to whatever you want. Just use