public string ReadBytesUntilNull(byte[] data, ref int i)
{
char nterm = '\0'; // Null terminator
int endpos = i;
int startpos = i;
// Find the null character
for (int j = i; j < data.Length; j++)
{
char spot = Convert.ToChar(data[j]);
if (spot == nterm)
{
endpos = j;
break;
}
}
// if we got to the end, then it's a zero length string
if (i == endpos)
{
// advance the 1 null character
i++;
return string.Empty;
}
else
{
// We found the end of the string
// append the bytes from the beginning of the string to the end of the string
// advance i
byte[] interm = new byte[endpos - i];
for (; i < endpos; i++)
{
interm[i - startpos] = data[i];
}
i++; // advance past the null character
return Utils.BytesToString(interm);
}
}