Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# IO discarding escape sequences

Posted on 2014-02-08
6
Medium Priority
?
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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