Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# IO discarding escape sequences

Posted on 2014-02-08
6
Medium Priority
?
237 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 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 400 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 400 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1200 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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