OpenMetaverse.BinBVHAnimationReader.ReadBytesUntilNull C# (CSharp) Method

ReadBytesUntilNull() public method

Variable length strings seem to be null terminated in the animation asset.. but.. use with caution, home grown. advances the index.
public ReadBytesUntilNull ( byte data, int &i ) : string
data byte The animation asset byte array
i int The offset to start reading
return string
        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);
            }
        }