They are obviously not identical, since you need to truncate an extra char
to make it work correctly. So find out what that extra char
actually is. Either the stream data has garbage in it to begin with, or the code that is reading the AnsiString from the stream has a logic bug in it that is introducing garbage.
When you use the debug inspector, make sure you are taking the AnsiString's entire length into account. By default, the inspector treats an AnsiString as a null terminated string and thus stops displaying data when it encounters the first null character it finds, so you might need to use the inspector's "Range" option to see everything that is actually present in the AnsiString's memory.