Solved

C# IO discarding escape sequences

Posted on 2014-02-08
6
229 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 62

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 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