Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,927
    Thanks
    46
    Thanked 203 Times in 202 Posts

    C# escape \n\t issue

    I have a streamwriter and I pass a string to it- it does not pick up my escapes though (\n\t) Please see below code nips

    the streamwriter section
    Code:
    if (EnableDetailedLog == "1")
                {
                    string LogFileDir = @"C:\";
                    string LogFilePath = LogFileDir + "DetailedLog" + DateTime.Now.ToString("MMddyyyy") + ".txt";
                    StreamWriter sw_LogFile = new StreamWriter(LogFilePath, true);
                    FileStream fs_LogFile = null;
    
                    try
                    {
                        if (!File.Exists(LogFilePath))
                        {
                            fs_LogFile = File.Create(LogFilePath);                        
                            sw_LogFile.WriteLine(string.Format("{0}  {1}\n", DateTime.Now, DetailedEntry).Trim());
                            fs_LogFile.Close();
                        }
    
                        else
                        {
                            sw_LogFile.WriteLine(string.Format("{0}  {1}\n", DateTime.Now, DetailedEntry).Trim());
                            sw_LogFile.Close();
                        }
    
                    }
    and then it get's passed things like this...
    Code:
    str_Contents[0] = string.Format("Last synchronization date was: {0:MM/dd/yyyy}.\n\t Upload failed, Download Failed.", DateTime.Now);
                str_Contents[1] = string.Format("Last synchronization date was: {0:MM/dd/yyyy}.\n\t Upload succeeded, Download Failed.", DateTime.Now);
                str_Contents[2] = string.Format("Last synchronization date was: {0:MM/dd/yyyy}.\n\t Upload succeeded, Download succeeded.", DateTime.Now);
    
    .........
    
     DetLog.DetailedLogEntry(string.Format("{0} {1}", str_Contents[0], str_Contents[3].Trim()));
    instead of newline and then tabbing (\n new line \t horizontal tab) it just "appends" a tiny box [] at the end (now two bracket chars though, an actual square).... does anyone know why it is not picking up my escapes?

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    What you have looks ok, I'm a little unclear where that second block of code is coming from. Is that in the debug visualizer or in the log file when you look at it does it not have things on different lines?
    OracleGuy

  • #3
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,927
    Thanks
    46
    Thanked 203 Times in 202 Posts
    sorry for the ambiguity- the first block of code is a snip from a function inside a class I made... so the class looks something like
    Code:
    public class DetailedLogger
    {
      public void DetailedLog(string args)
      {
    ....... then the stuff I have up there ....
      }
    }
    so what happens then is in my main program I do
    Code:
    DetailedLogger DetLog = new DetailedLogger();
    and then I pass it arguments to that fxn within it via
    Code:
    DetLog.DetailedLog(MyString);
    but it does not keep the escapes

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Sorry for the delay in responding. Did you get it figured out? It might be because you are using Unix line ending (\n) and wherever you are displaying this is expecting windows ones (\r\n). Or if you want Environment.NewLine.
    OracleGuy

  • #5
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,927
    Thanks
    46
    Thanked 203 Times in 202 Posts
    i have not figured it out yet... i thought about using \r as well thinking that might be the issue... i haven't had a chance to implement it to test though... no worries on delay getting back- i was delayed as well - i will post back if the \r works (and i'll check the link u provided as well)

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,927
    Thanks
    46
    Thanked 203 Times in 202 Posts
    This is resolved... apparently it was the need for the \r... I got my answer too late to mark as resolved though- if any mod wants to mark it as such would be greatly appreciated

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •