コード例 #1
0
        /*----------------------------------------------------------------------------
        *       %%Function: StmCreateFromString
        *       %%Qualified: TCore.Debug.DebugStream.StmCreateFromString
        *       %%Contact: rlittle
        *
        *   it turns out, writing a string to a file in .net isn't as simple as you
        *   would think. The strings are unicode, and you were probably thinking
        *   about just plain ascii. so, this will create a stream the way you think
        *   it would (converting the ascii to bytes, and encoding \n as CRLF
        *   (0x0d0x0a)
        *  ----------------------------------------------------------------------------*/
        public static DebugStream StmCreateFromString(string s)
        {
            DebugStream stm = new DebugStream();

            foreach (char ch in s)
            {
                switch (ch)
                {
                case '\n':
                    stm.Write(new byte[] { 0x0d, 0x0a }, 0, 2);
                    break;

                case (char)0x240d:
                    stm.Write(new byte[] { 0x0d }, 0, 1);
                    break;

                case (char)0x240a:
                    stm.Write(new byte[] { 0x0a }, 0, 1);
                    break;

                default:
                    stm.WriteByte((byte)ch);
                    break;
                }
            }

            return(stm);
        }