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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C# Searching a textfile

  • 13-03-2007 11:35am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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