Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6982893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:20:52+00:00 2026-05-27T18:20:52+00:00

I have a file which is in this format: AA AA AA AA AA

  • 0

I have a file which is in this format:

AA
AA AA AA
AA AA AA AA AA AA
AA AA AA
file.txt
0

Where AA represents a one or two digit number (the length of each doesn’t have to be 2), and file.txt is the name of a file. I need a very fast method to obtain the file name. Also, I need to replace the final 0 with 1. If there is no 0 in the file at the end (its optional), I need to append 1 on a new line. Here is my current code:

StringBuilder sb = new StringBuilder("\r\n1");
string txt = File.ReadAllText(args[0]);
string[] lines = txt.Split('\n');
string name = lines[4];

if (lines.Length != 6) // Check if EOF is 0 or not.
    txt += sb.ToString();
else
    txt = txt.Substring(0, txt.Length - 1) + '1'; // Replace 0 with 1.

File.WriteAllText(args[0], txt);
Console.WriteLine(name);

However, I was wondering if there was even a faster way to do this (without having to load the file in memory maybe). I have to process tons of files like this, so saving tenths would be extremely useful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:20:53+00:00Added an answer on May 27, 2026 at 6:20 pm
    var lines = new List<string>(File.ReadAllLines(args[0]));
    string name = lines[4];
    
    if (lines.Length != 6) // Check if EOF is 0 or not.
        lines.Add("1");
    else
        lines[5] = "1";
    
    File.WriteAllLines(args[0], lines);
    Console.WriteLine(name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an external log file which name changes each session, with the format
I have this exported file of some weird (standard for this industry!) format, which
I have this file file.txt which I want to split into many smaller ones.
I have this code which will include template.php file from inside each of these
I have a file with one phrase/terms each line which i read to perl
I have a txt file which has data in the below format: int string
I have a .txt file which has about 500k entries, each separated by new
i have a DTD file which i used to accessed through this link: http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd
I have a php file which has a require_once Statement (?) this file is
I have a bash script file which starts with a function definition, like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.