Following on from all this, I have a byte array of whatever length containing ASCII.
The first 36bytes look like this;
1byte=check
4byte=referencenumber
30byte=username
1byte=numberoflines
So as none of these parts change or reoccur I've pulled them out and converted them to string from ASCII or whatever, as required.
The tricky bit (for me at least) is the next part;
The number of lines refers to how many actions have taken place, in the following sense;
numberoflines byte = 3
so;
One line:
30bytes=action
1byte=number
30bytes=action
1byte=number
Two line:
30bytes=action
1byte=number
30bytes=action
1byte=number
And so on. hopefully that illustrates the case.
Now the problem I'm having is building a for loop to tell itself that by reading the number of lines, it has to;
convert 30bytes into string (print it)
converted 1 into decimal (print it)
convert 30 into string (print it)
convert 1 into decimal (print it)
(one line done)
convert 30bytes into string (print it)
convert 1 into decimal (print it)
convert 30 into string (print it)
convert 1 into decimal (print it)
(second line done).
So far I have this little method;
Code:
int bytelength = recmessage.length;
int beginline = 36;
int m = 65;
int n = 66;
while (beginline <= bytelength) {
String cut = new String(reply.getData(), beginline, m);
out.print("Action:" + cut);
int amount = recmessage[n];
out.print("£ " + amount + "\n");
beginline = beginline + 32;
n = n + 31;
m = m + 30;
out.print("<br>");
}
Problem is it doesnt work, gives me;
java.lang.StringIndexOutOfBoundsException: String index out of range: 1031
Also, how does the method look? Its been bugging for an hour or so and I've only just put the logic into code as above.
Thanks in advance for any help.