The variable productQR will have a string value of the format <rate>,<quantity>@<rate>,<quantity>@<rate>,<quantity>.
To give an example,
productQR = "250,10@100,3@50,7" will have the Rate as 250, 100 and 50 while Quantity as 10, 3 and 7 respectively. How can I assign those values to Rate1, Rate2 and Rate3 respectively? Same for the Quantity variable?
This is the function:
String calcGST(Receipt r) {
String regex = "[\d]+[,]{1}[\d]+[@]{1}[\d]+[,]{1}[\d]+[@]{1}[\d]+[,]{1}[\d]+";
Pattern p = Pattern.compile(regex);
r.productQR = Rate + "," + q1 + "@" + Rate2 + "," + q2 + "@" + Rate3 + "," + q3;
return null;
}
this is the receipt class:
class Receipt {
TransactionParty transactionParty;
String productQR;
public Receipt(TransactionParty transactionParty, String productQR) {
super();
this.transactionParty = transactionParty;
this.productQR = productQR;
}
}
What I have tried:
I tried using regex/.split() but I don't know how can we extract values from it.