Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# Searching a textfile

Options
  • 13-03-2007 12:35pm
    #1
    Registered Users Posts: 1,987 ✭✭✭


    I've hit a wall, i've looked everywhere, anyone have any idea on how to search a text file for keywords and extract them?


Comments

  • Closed Accounts Posts: 884 ✭✭✭NutJob


    break open MSDN

    Look at File
    look at StreamReader in c#
    look at String in c#


    Use the many string handling functions


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Also google for "regex".


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    I was thinking of using the string comparison function in C#, any draw backs from using it?


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    No drawbacks, it's just Regex can match your entire file, pull out all your results and have them all ready for you to operate on if needed all with two lines:

    Regex r = new Regex("MyMatchString");
    RegexMatchCollection matches = regex.Matches(myString);

    Or something like that. You can do some pretty complex stuff in regex's if you want, or just some bog standard "find all occurances of X".


Advertisement