Issue to CR LF

Peter_1985 2,666 Reputation points
2024-09-05T04:37:00.5+00:00
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,843 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 31,011 Reputation points Microsoft Vendor
    2024-09-06T07:18:41.6066667+00:00

    Hi @Peter_1985 ,

    You can add an additional check to ensure that the last line contains the correct CR LF (\r\n) terminator. If it’s missing, append the necessary CR LF terminator.

    
    string filePath = "file.edi";
    var lines = File.ReadAllLines(filePath);
    
    string lastLine = lines.Last();
    
    if (!lastLine.EndsWith("\r\n"))
    {
        lines[lines.Length - 1] += "\r\n";
    
        File.WriteAllLines(filePath, lines);
    }
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.