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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:29:52+00:00 2026-06-02T00:29:52+00:00

Currently I am building an agenda with extra options. for testing purposes I store

  • 0

Currently I am building an agenda with extra options.

for testing purposes I store the data in a simple .txt file
(after that it will be connected to the agenda of a virtual assistant.)

To change or delete text from this .txt file I have a problem.
Although the part of the content that needs to be replaced and the search string are exactly the same it doesn’t replace the text in content.

code:

Change method

public override void Change(List<object> oldData, List<object> newData)
    {
        int index = -1;
        for (int i = 0; i < agenda.Count; i++)
        {
            if(agenda[i].GetType() == "Task")
            {
                Task t = (Task)agenda[i];

                if(t.remarks == oldData[0].ToString() && t.datetime == (DateTime)oldData[1] && t.reminders == oldData[2])
                {
                    index = i;
                    break;
                }
            }
        }

        string search = "Task\r\nTo do: " + oldData[0].ToString() + "\r\nDateTime: " + (DateTime)oldData[1] + "\r\n";
        reminders = (Dictionary<DateTime, bool>) oldData[2];
        if(reminders.Count != 0)
        {
            search += "Reminders\r\n";

            foreach (KeyValuePair<DateTime, bool> rem in reminders)
            {
                if (rem.Value)
                    search += "speak " + rem.Key + "\r\n";
                else
                    search += rem.Key + "\r\n";
            }
        }

        // get new data
        string newRemarks = (string)newData[0];
        DateTime newDateTime = (DateTime)newData[1];
        Dictionary<DateTime, bool> newReminders = (Dictionary<DateTime, bool>)newData[2];

        string replace = "Task\r\nTo do: " + newRemarks + "\r\nDateTime: " + newDateTime + "\r\n";
        if(newReminders.Count != 0)
        {
            replace += "Reminders\r\n";
            foreach (KeyValuePair<DateTime, bool> rem in newReminders)
            {
                if (rem.Value)
                    replace += "speak " + rem.Key + "\r\n";
                else
                    replace += rem.Key + "\r\n";
            }
        }

        Replace(search, replace);

        if (index != -1)
        {
            remarks = newRemarks;
            datetime = newDateTime;
            reminders = newReminders;
            agenda[index] = this;
        }
    }

replace method

    private void Replace(string search, string replace)
    {
        StreamReader reader = new StreamReader(path);
        string content = reader.ReadToEnd();
        reader.Close();

        content = Regex.Replace(content, search, replace);
        content.Trim();

        StreamWriter writer = new StreamWriter(path);
        writer.Write(content);
        writer.Close();
    }

When running in debug I get the correct info:

    content "-- agenda --\r\n\r\nTask\r\nTo do: test\r\nDateTime: 16-4-2012 15:00:00\r\nReminders:\r\nspeak 16-4-2012 13:00:00\r\n16-4-2012 13:30:00\r\n\r\nTask\r\nTo do: testing\r\nDateTime: 16-4-2012 9:00:00\r\nReminders:\r\nspeak 16-4-2012 8:00:00\r\n\r\nTask\r\nTo do: aaargh\r\nDateTime: 18-4-2012 12:00:00\r\nReminders:\r\n18-4-2012 11:00:00\r\n"    string

    search  "Task\r\nTo do: aaargh\r\nDateTime: 18-4-2012 12:00:00\r\nReminders\r\n18-4-2012 11:00:00\r\n"  string

    replace "Task\r\nTo do: aaargh\r\nDateTime: 18-4-2012 13:00:00\r\nReminders\r\n18-4-2012 11:00:00\r\n"  string

But it doesn’t change the text. How do I make sure that the Regex.Replace finds the right piece of content?

PS. I did check several topics on this, but none of the solutions mentioned there work for me.

  • 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-06-02T00:29:53+00:00Added an answer on June 2, 2026 at 12:29 am

    You missed a : right after Reminders. Just check it again 🙂

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

Sidebar

Related Questions

I'm currently building a simple app that overlaps one image on top of another.
Currently building a WPF app that will run in an environment where the user
Currently building an app that runs on mobile phones not related to the issue
I am currently building a measurement unit convertion app for Windows Phone. After setting
I am currently building a Rails 3.2 application that uses the gem sunspot to
I am currently building a Website that uses a blackletter font. I try to
We are currently building a PostgreSQL database that allows us to create profiles for
I'm currently building an app that contains around 60 or so tables, some with
I'm currently building a web application that has multiple user types, where users engage
I am currently building a data structure which relies a lot on efficiency. Can

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.