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 3873728
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:04:13+00:00 2026-05-19T22:04:13+00:00

I have a text file that is almost sometimes 5 mb large. What I

  • 0

I have a text file that is almost sometimes 5 mb large. What I need to do is write a function that Finds Start and end mark, there can be many such marks. And apply replace to the found words that are between the marks with some random string and save back to the file
For example,
Suppose I have following string,

{one} hellow there {one} this will not be replaced as it is not within marks {two}you again{two}

so the resultant content would be

{one} someRandomText AgainSomeRandomText {one} this will not be replaced as it is not within marks {two} moreRandom againMoreRandom{two}

How do I do this in C#

  • 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-19T22:04:13+00:00Added an answer on May 19, 2026 at 10:04 pm

    One relatively easy option, which may not be the best solution depending on how many threads could be concurrently reading from different files, is to read the entire file into a string in memory and then use Regex to find the location of all {one} sections.

    Using the Regex::Match::Index and Regex::Match::Length properties, you can find the start and and end your matching sections. Looping through all your matches, use these two properties to generate your new text string, which can either be written to a new file as your looping or at the very end.

    If you would rather not load the entire file into a string, you’ll have to have a stream that reads and a stream that writes to a new file. Read the file sections at a time while looking for your {one} (start) tag. Then replace everything after it with your new string until you find the closing {/one} tag. Once all is said and done, delete the old file, then rename the new file to the old file’s filename.

    Anyway, just a couple solutions. I’d have to see what all your project entails in order to better answer your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.