简体   繁体   中英

Read data from barcode

I have one question regarding about retrieving Barcode data.

Below screen shot is the my java application. 在此处输入图片说明

For example, the barcode data have "12345-6789". I put cursor on "Mo No." and scan barcode, System will read barcode and display on "Mo No." filled as "12345-6789"

But what I want is "12345" in Mo No. and "6789" in Container No. Once I scanned barcode. How should I implement the code. Please advice.Thanks.

Use String#split

String toSplit = "12345-6789";
String a;
String b;
//check if string contains your split-char with [string#contains][2])
if(toSplit.contains("-")
{
  //split takes RegularExpression!
  String[] parts = toSplit.split("-");
  a = parts[0]; // =12345
  b = parts[1]; // =6789
}
else
{
  throw new IllegalArgumentException(toSplit + " does not contain -");
}

you can just ignore whatever after dash -

for example:

    String barcode="12345-6789";
    System.out.println(barcode.substring(0,barcode.indexOf("-"))); //this will only print whatever before first occurance of '-'

OUTPUT:

12345

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM