Solved

C# IO discarding escape sequences

Posted on 2014-02-08
6
232 Views
Last Modified: 2014-02-12
Hello Experts,

I am trying to load a template in c# as a text file.  It works pretty well but I am running into problems because I am losing the escape sequences during the load.  Can someone tell me how to load a text file that can include quotes?  If there is better way to do this?

below you'll find a portion of the method I am working with:

using (StreamReader SR = new StreamReader(Data))
            {
                string line="";
                while ((line = SR.ReadLine()) != null)
                {
                    ProcessLine(line);
                }
                SR.Close();
                SR.Dispose();
            }

Thank you in advance!

Fox
0
Comment
Question by:the_b1ackfox
6 Comments
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 100 total points
ID: 39844852
You state the following, "I am losing the escape sequences during the load.", Which escape sequences are you losing?

Can you give an example of the file when stored in the file system and what happens to it after loading it into memory.
0
 
LVL 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 100 total points
ID: 39844853
c#'s readline will not leave any character behind when reading it from file.
Can you please give us the part of the file that is being read, in which some characters are getting missed?
0
 
LVL 9

Author Comment

by:the_b1ackfox
ID: 39844963
After seeing both of your requests, I made up a file to demonstrate what was going on.  The only problem is that the issue did not show up in the file I created.  So that go t me thinking about the file I had originally used...  I *did* cut and paste almost all of the file and then saved it as a text file.   So before this goes any further, I think I will recreate the template manually first as there may have been something that slipped into the file with a paste...
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 300 total points
ID: 39845005
It can simply be a problem with the encoding. Try one of the alternative constructors, either the one that tries to detect encoding, or the one where you define a specific encoding. Try different encodings until you find the right one:

new StreamReader(data, True)
new StreamReader(data, System.Text.Encoding.UTF8)
0
 
LVL 9

Author Comment

by:the_b1ackfox
ID: 39854122
James, you are probably correct.  But after some thinking about my overall objective, I decided to make a tactical change.  (ie, I wouldn't have to deal with working through some of the additional objectives if I made a strategic change now, lol)  

I have abandoned the process for a better one and I am past this issue.  Thank you all.
0
 
LVL 9

Author Closing Comment

by:the_b1ackfox
ID: 39854141
Fernando and Surendra, your responses helped me increase my perspective by having me go back to the basics and reexamine what I was doing.  James, your response gave me insight and knowledge which I value.

Thank you all!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question