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

  • Home
  • SEARCH
  • 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 7830861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:26:08+00:00 2026-06-02T11:26:08+00:00

I need to develop a Phonebook. I write my contacts data to a text

  • 0

I need to develop a Phonebook.

I write my contacts data to a text file and I work with console. What options do I have to SEARCH and DELETE a contact in that text file?

This is how I am inserting contacts:

public class Writer
{
    public void  writer (string name,string lastname,string number)
    {
        StreamWriter Wrt = new StreamWriter("D:\\Sample.txt",true);
        Wrt.Write(name);
        Wrt.Write(lastname);
        Wrt.Write(number);
        Wrt.Write("#");
        Wrt.Write("");
        Wrt.Close();
    }
}
  • 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-02T11:26:10+00:00Added an answer on June 2, 2026 at 11:26 am

    Each line correspond to a contact, right? What is your criteria to delete a contact? If you are looking for a name and lastname, you can do this.

    string line = null; 
    string Criteria = name + " " lastname;
    
    using (StreamReader reader = new StreamReader("C:\\input"))
    { 
      using (StreamWriter writer = new StreamWriter("C:\\output"))
      { 
        while ((line = reader.ReadLine()) != null)
        { 
          if (line.Contains(Criteria)) 
            continue; 
    
          writer.WriteLine(line); 
        } 
      } 
    } 
    

    This will read your file and write all contacts you want to keep in another file.

    However, if you want to keep the same file (or if your contacts info are on more than one line). You can read the whole file and keep it in memory, remove those you do not want, and then write the file again.

    //Method with a class containing the info because informations are on several lines
    Contact[] contacts = MethodToRead("filename.txt"); 
    Contact[] filteredContacts = methodFilterContacts(contacts ); 
    foreach(Contact c in filteredContacts)
    {
         //Call your write method mentionned
         Writer.writer(c.name, c.lastname, c.number);
    }
    
    //Method if contact on only one line
    string[] contactLines = File.ReadAllLines("filename.txt"); 
    string[] filteredContactLines = methodFilterContacts(contactLines ); 
    //This will write everything as is
    File.WriteAllLines("filename.txt", filteredContactLines ); 
    

    That was if you want to keep your text file. As it was suggested earlier, you can use xml to write and read an easier to maintain file. If you know the basics of xml, or up for a little challenge (and have time for it), it might be a better way to go.

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

Sidebar

Related Questions

I need to develop a page which has 2 dropdownlist. Options of dropdownlist 2
I need develop a Java UI similar to windows explorer. The interface should have
I need to develop a lightweight web application, it will: have a simple webgui
I need to develop a real-time monitoring solution. there is a data source that
I need to develop a scraping tool that scrapes product's data (price, title etc)
I need to develop a file sharing apps over the internet by p2p. I
I need to develop an app that is using multithreading. Basicly, I have a
I need to develop a Facebook application. I have generated the application ID and
I need to develop an IFilter for Microsoft Search Server 2008 that performs prolonged
I need to develop a website that work on Blackberry. Please suggest me the

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.