Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. StreamWriter reformatting output???

StreamWriter reformatting output???

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LongRange Shooter
    wrote on last edited by
    #1

    I have code that walks through the properties of an object and writes out the property name and value in UTF-16 format. One of the fields has a string date and time formatted as follows: yyyy-MM-ddThh:mm:ss When I step through the code, the data sent to my writer is formatted correctly. When I look at the output, however, it is now: yyyy-MM-dd hh:mm:ss AM. I know that it is not my writer logic doing this because it always just works with the object.ToString() method on everything. The base type of this object is string, not DateTime. First of all I cannot believe that StreamWriter is reformatting the data. Secondly I need to have it kept in the original format. Any suggestions to tell StreamWriter to keep its' hands off my data would be appreciated.

    C 1 Reply Last reply
    0
    • L LongRange Shooter

      I have code that walks through the properties of an object and writes out the property name and value in UTF-16 format. One of the fields has a string date and time formatted as follows: yyyy-MM-ddThh:mm:ss When I step through the code, the data sent to my writer is formatted correctly. When I look at the output, however, it is now: yyyy-MM-dd hh:mm:ss AM. I know that it is not my writer logic doing this because it always just works with the object.ToString() method on everything. The base type of this object is string, not DateTime. First of all I cannot believe that StreamWriter is reformatting the data. Secondly I need to have it kept in the original format. Any suggestions to tell StreamWriter to keep its' hands off my data would be appreciated.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I think we need to see the code, I doubt very much that a streamwriter would reformat a datetime.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      L 1 Reply Last reply
      0
      • C Christian Graus

        I think we need to see the code, I doubt very much that a streamwriter would reformat a datetime.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        L Offline
        L Offline
        LongRange Shooter
        wrote on last edited by
        #3

        Christian, Trust me, I've been saying the same thing myself. Below is the code. I commented the line where I verified the format was still dateTtime and then looked at the output that was put to the file in notepad to see that the format was now data time AM. Messed up my head something fierce.

        public sealed class Serialize:IDisposable
        {
            static StreamWriter output;
            //static FileStream output;
        
            /// <summary>
            /// Writes an opening Xml node to the stream
            /// </summary>
            /// <param name="fieldName"></param>
            public static void WriteOpen(string fieldName)
            {
                string buffer = String.Format("<{0}>", fieldName);
                //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length);
                output.Write( buffer );
            }
        
            /// <summary>
            /// Writes a closing Xml node to the stream
            /// </summary>
            /// <param name="fieldName"></param>
            public static void WriteClose(string fieldName)
            {
                string buffer = String.Format("</{0}>", fieldName);
                //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length);
                output.Write( buffer );
            }
        
            /// <summary>
            /// Writes a raw line of data to the stream
            /// </summary>
            /// <param name="rawData"></param>
            public static void WriteRaw(string rawData)
            {
                //output.Write(Encoding.UTF8.GetBytes(rawData), 0, rawData.Length);
                output.Write( rawData );
            }
        
            /// <summary>
            /// Writes a formatted Xml line of data to the stream
            /// </summary>
            /// <param name="fieldName"></param>
            /// <param name="value"></param>
            public static void WriteLine(string fieldName, string value)
            {
                if (value.Length.Equals(0))
                {
                    string buffer = String.Format("<{0} />", fieldName);
                    //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length);
                    output.Write( buffer );
                }
                else
                {
                    string buffer = String.Format("<{0}>{1}</{0}>", fieldName, value);
                    //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length);
                    // THIS IS WHERE I BROKE THE CODE AND  VERIFIED THE BUFFER DATA PASSED TO
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups