Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C# Searching a textfile

  • 13-03-2007 12:35PM
    #1
    Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭


    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, Registered Users 2 Posts: 1,991 ✭✭✭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