Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Replicate Textpad's file format setting

I've written a C# program to process a file.  It only works if I open the file in textpad and go to save as.  There are two options at the bottom of the dialogue.  They are file format and encoding.  I must change the file format from "no change" to "PC".  
What's the difference between the two formats?
How can I achieve this programmatically?
I'm using C# for windows programming with visual studio 2008.
0
AlHal2
Asked:
AlHal2
  • 5
  • 3
1 Solution
 
Luis PérezSoftware Architect in .NetCommented:
When your program doesn't work, is it throwing any exception? If so, can you post that?
0
 
AlHal2Author Commented:
It's inputting the first line and ignoring subsequent lines.  I opened the input file in hexedit.  It seems like the lines are ending with characters 13,10,13 instead of 13,10.
13=carriage return.  10= line feed.
0
 
Luis PérezSoftware Architect in .NetCommented:
Can you attach both files, one of them "as is" and another one saved in TextPad? So I can see the differences between them and see if there's any way in .Net to replicate that...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
AlHal2Author Commented:
Please take a look.
RawFile.txt
RawFileAfterTextpad.txt
0
 
AlHal2Author Commented:
Please ignore rawfileaftertexpad.txt.
Compare rawfile.txt with rawfileaftertextpad2.txt which I'm just attaching.  Sorry for the confusion.
RawFileAfterTextpad2.txt
0
 
AlHal2Author Commented:
Please let me know if anything is unclear.
0
 
Luis PérezSoftware Architect in .NetCommented:
Ok, after deep looking at both files, I've seen what's the difference. The first one uses the Macintosh style for line breaks, which is the contatenation of Carriage Return + Carriage Return + Line Feed (ascii characters 13+13+10); the second one uses the Dos/Windows style, which is only Carriage Return + Line Feed (ascii 13+10).

You can use this simple function to convert one file from Mac style to Windows style (it uses the System.IO namespace):

private void convertMacToWindows(string fileName)
{
    string macText = File.ReadAllText(fileName);
    string macNewline = ((char)13).ToString() + ((char)13).ToString() + ((char)10).ToString();
    string pcNewline = ((char)13).ToString() + ((char)10).ToString();
    string pcText = macText.Replace(macNewline, pcNewline);
    File.WriteAllText(fileName, pcText);
}

Open in new window

Please, try it and tell me if it works now.

Hope that helps.
0
 
AlHal2Author Commented:
Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now