1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

search for a string in a file

Discussion in 'C#' started by shah123, Apr 10, 2007.

  1. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    How to search for a string in a file. As string might be somewhere in the middle of text file.
    Code:
    Console.WriteLine("Input a string ");
    String data = Console.ReadLine();
    sr = File.OpenText(@"C:\username.txt");
    
    String st = sr.ReadToEnd();
    ?????
    
    help please?

    thanks
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    use st.Contains
     
  3. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Shabbir Brother you are the star. Thanks a million
     
  4. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    One more question is

    "How to find a position of that string in a file"?

    Rgds,
     
  5. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    I got the answer for position thanks anyway
     

Share This Page