Hi All
good syntax:
byte data[]=new data[100];
if (data.startsWith(12,43,32)){
}
thanks
from Peter (cmk128@hotmail.com)
Massimo_X_Meridio - 27 Sep 2005 12:37 GMT
> Hi All
> good syntax:
[quoted text clipped - 6 lines]
> thanks
> from Peter (cmk128@hotmail.com)
Hi peter
Data is an array of byte not a class!
Good syntax: byte data[]=new byte[100];
Second:if data can't be a class it can't have a method like startsWith().
Regards Max_X_Meridio
Thomas Schodt - 27 Sep 2005 13:15 GMT
> byte data[]=new data[100];
I would prefer
byte[] data=new byte[100];
> if (data.startsWith(12,43,32)){
Looks like you are thinking perl;
my @data;
$#data = 99;
if (@data[0 .. 2] == (12,43,32)){
cmk128@hotmail.com - 27 Sep 2005 15:06 GMT
yes, Java syntax never have surprise.
drkn - 27 Sep 2005 20:42 GMT
>> byte data[]=new data[100];
>
> I would prefer
> byte[] data=new byte[100];
Syntax is ok in both cases and its not the biggest problem for this guy...
;)
>> if (data.startsWith(12,43,32)){
>
[quoted text clipped - 4 lines]
>
> if (@data[0 .. 2] == (12,43,32)){

Signature
drkn
Thomas Schodt - 28 Sep 2005 00:30 GMT
>>> byte data[]=new data[100];
>>
>> I would prefer
>> byte[] data=new byte[100];
>
> Syntax is ok in both cases
new data[100];
new byte[100];
^_^
drkn - 28 Sep 2005 21:38 GMT
> new data[100];
>
> new byte[100];
>
> ^_^
Ups... :/ My oversight.

Signature
drkn
Thomas Hawtin - 27 Sep 2005 19:54 GMT
> byte data[]=new data[100];
>
> if (data.startsWith(12,43,32)){
> }
Nothing to stop you writing:
public static boolean startsWith(byte[] target, byte... start) {
int num = start.length;
if (target.length < num) {
return false;
}
for (int ct=0; ct<num; ++ct) {
if (target[ct] != start[ct]) {
return false;
}
}
return true;
}
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Roedy Green - 27 Sep 2005 20:32 GMT
>byte data[]=new data[100];
>
>if (data.startsWith(12,43,32)){
>}
// see http://mindprod.com/jgloss/naming.html why data is not a good
// name
byte temperatures = new byte[ 100 ];
// ... code to set temperatures
if ( temperatures[0] == 12
|| temperatures[1] == 43
|| temperatures[2] == 32 ) ...
you could write a static method boolean startsWith( byte[], byte[] )
or startsWith( byte[], byte... );
then you could write:
if ( startsWith( temperatures, new byte[]{ 12, 43, 32 } ) ) ...
Not as tidy as you wanted but Java was never big on terseness.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.