I have a memory stream with an XML document in it, created using the
XmlTextWriter. I wanted to put the memory stream into a string, so
that I could perform some Regular Expression work on the string.
Everything works great, except that this,
sStr = Encoding.UTF8.GetString(objStream.ToArray())
returns a string with a "garbage" character at the beginning that I
have to first strip before using the result, with this,
sStr = sStr.Remove(0, 1)
I've read that when using the "Encoding" class, that there can
be "special encoding characters" purposely present at the beginning
of the string. This is just annoying, and presents the overhead of a
string copy in the extra step! Is there a better way to get a stream
into a string?