Why not use the ReadToEnd()
method of a StreamReader class, then work backwards...
Admittedly it is not pretty but it works, I used a byte array to create a MemoryStream
instance and the use that for the StreamReader
instance, using pointer hocus-pocus, the data is read in a backward fashion.
unsafe
{
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes("Hello World! Foo wuz ere and so wuz bar");
using (MemoryStream mStream = new MemoryStream(b))
{
string readStr;
using (StreamReader sr = new StreamReader(mStream))
{
readStr = sr.ReadToEnd();
}
Console.WriteLine(readStr);
fixed (char* beg = readStr)
{
char* p = beg + readStr.Length;
while (p-- != beg)
{
Console.Write(*p);
}
}
}
}
Hope this helps,
Best regards,
Tom.