我有一个长度为16的字符串uniqueCode。

String uniqueCode = accountno + extracode;


accountno的长度为6,并且通过以下方式填充Extracode:

String extraCode = branch + loanCode + openingDateStr ;
BigInteger hexaCode = new BigInteger(extraCode);
extraCode = hexaCode.toString(16); // hexa bit


现在我想从这个唯一的代码中获得分支,贷款代码和openingdatestr。
这个怎么做?

最佳答案

要从extraCode以十六进制取回原始字符串:

BigInteger decCode = new BigInteger(extraCode, 16);
extraCode = decCode.toString(10);


现在您可以按长度从extraCode中提取组件。例如,如果branch有6位数字,而loanCode有4位数字,则可以执行以下操作:

String branch = extraCode.substring(0, 6);
String loanCode = extraCode.substring(6, 10);

10-06 15:33