System.IO.StreamWriter.WriteLine C# (CSharp) Method

WriteLine() public method

public WriteLine ( string value ) : void
value string
return void
        public override void WriteLine(string value)
        {
            if (value == null)
            {
                value = String.Empty;
            }

            CheckAsyncTaskInProgress();

            int count = value.Length;
            int index = 0;
            while (count > 0)
            {
                if (_charPos == _charLen)
                {
                    Flush(false, false);
                }

                int n = _charLen - _charPos;
                if (n > count)
                {
                    n = count;
                }

                Debug.Assert(n > 0, "StreamWriter::WriteLine(String) isn't making progress!  This is most likely a race condition in user code.");
                value.CopyTo(index, _charBuffer, _charPos, n);
                _charPos += n;
                index += n;
                count -= n;
            }

            char[] coreNewLine = CoreNewLine;
            for (int i = 0; i < coreNewLine.Length; i++)   // Expect 2 iterations, no point calling BlockCopy
            {
                if (_charPos == _charLen)
                {
                    Flush(false, false);
                }

                _charBuffer[_charPos] = coreNewLine[i];
                _charPos++;
            }

            if (_autoFlush)
            {
                Flush(true, false);
            }
        }

Usage Example

Example #1
1
        public void exportCSV(string filename)
        {
            StreamWriter tw = new StreamWriter(filename);

            tw.WriteLine("Filename;Key;Text");
            string fn;
            int i, j;
            List<string> val;
            string str;

            for (i = 0; i < LTX_Texte.Count; i++)
            {
                fn = LTX_Texte[i].Key.ToLower().Replace(".ltx","");
                val = LTX_Texte[i].Value;
                for (j = 0; j < val.Count; j++)
                {
                    str = prepareText(val[j], true);
                    if( str != "" )
                        tw.WriteLine(fn + ";" + j.ToString() + ";" + str);
                }
            }
            for (i = 0; i < DTX_Texte.Count; i++)
            {
                fn = DTX_Texte[i].Key.ToLower().Replace(".dtx","");
                val = DTX_Texte[i].Value;
                for (j = 0; j < val.Count; j++)
                {
                    str = prepareText(val[j], true);
                    if (str != "")
                        tw.WriteLine(fn + ";" + j.ToString() + ";" + str);
                }
            }

            tw.Close();
        }
All Usage Examples Of System.IO.StreamWriter::WriteLine