I m试图生产一个许可证钥匙,有两条护法将两者合并成另一条str。
String key1 = "X1X2X3X4..Xn"; //this is for the imei key cellphone
String key2 = "Y1Y2Y3Y4M1M2D1D2H1H2m1m2"; //this is a key to mix with the first one
组合的结果应如此:
String result = "D1H1X1X2X3Y2Y4X4X5...XnY3Y1D2m2m1H1H2";
我将座右铭分成两处,我只把座椅分成一阵:
String [] key1splited = splitStringEvery(key1, 2);
String [] key2splited = splitStringEvery(key2, 2);
public String[] splitStringEvery(String s, int interval) {
int arrayLength = (int) Math.ceil(((s.length() / (double)interval);
String[] result = new String[arrayLength];
int j = 0;
int lastIndex = result.length - 1;
for (int i = 0; i < lastIndex; i++) {
result[i] = s.substring(j, j + interval);
j += interval;
}
result[lastIndex] = s.substring(j);
return result;
}
我怎么能够把我的发言结合起来,给我带来这样的结果:
String result = "D1H1X1X2X3Y2Y4X4X5...XnY3Y1D2m2m1H1H2";
我希望有人能给我一个如何解决这一问题的想法。
我正试图做这样的事情,但这种方法非常糟糕:
static String res = "";
String[] key1splited = splitStringEvery(key1, 2);
String[] key2splited = splitStringEvery(key2, 2);
for (int i = 0; i < key2splited.length; i++) {
if (key2splited[i].equals("D1")) {
res = key2splited[i];
}
if (key2splited[i].equals("H1")) {
res += key2splited[i];
for (int j = 0; j < key1splited.length; j++) {
if (key1splited[j].equals("X1")) {
res += key1splited[j];
}
if (key1splited[j].equals("X2")) {
res += key1splited[j];
}
if (key1splited[j].equals("X3")) {
res += key1splited[j];
}
}
}
}
因此,但这不能成为这样做的良好途径,因为扼杀物会发生变化。