Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Complete this program-- New bie to FileStream ?

Complete this program-- New bie to FileStream ?

Scheduled Pinned Locked Moved C#
csharpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cyberiafreak
    wrote on last edited by
    #1

    I'm new bie to C# application..here is my requirement goes, (a) I want to search a particular keyword inside a file. (b) let say, if a file contains text "this is sample program...". If i search "sample" inside a file, it should give the exact matching. (c) any prior articles for the same..? -------code FileStream fs = new FileStream("C:\\a.txt", FileMode.Open, FileAccess.Read); StreamReader fs1 = new StreamReader(fs); String mystring="sample"; while (string == fs1. _:doh:___ ) { Messagbox.show("Yes i got ur string .."); } --------- please reply this incomplete prog..snippet.

    D M 2 Replies Last reply
    0
    • C cyberiafreak

      I'm new bie to C# application..here is my requirement goes, (a) I want to search a particular keyword inside a file. (b) let say, if a file contains text "this is sample program...". If i search "sample" inside a file, it should give the exact matching. (c) any prior articles for the same..? -------code FileStream fs = new FileStream("C:\\a.txt", FileMode.Open, FileAccess.Read); StreamReader fs1 = new StreamReader(fs); String mystring="sample"; while (string == fs1. _:doh:___ ) { Messagbox.show("Yes i got ur string .."); } --------- please reply this incomplete prog..snippet.

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #2

      Read N chars (N = length of the string you're matching) from the filestream into a test string. Test the buffer against the search string. If they don't match delete the leading character from the test string, read a single character from the file, append it to the test string and test again. repeat until you find a match or reach the end of the file.

      1 Reply Last reply
      0
      • C cyberiafreak

        I'm new bie to C# application..here is my requirement goes, (a) I want to search a particular keyword inside a file. (b) let say, if a file contains text "this is sample program...". If i search "sample" inside a file, it should give the exact matching. (c) any prior articles for the same..? -------code FileStream fs = new FileStream("C:\\a.txt", FileMode.Open, FileAccess.Read); StreamReader fs1 = new StreamReader(fs); String mystring="sample"; while (string == fs1. _:doh:___ ) { Messagbox.show("Yes i got ur string .."); } --------- please reply this incomplete prog..snippet.

        M Offline
        M Offline
        maheswara
        wrote on last edited by
        #3

        public bool FindMyText(string text) { // Initialize the return value to false by default. bool returnValue = false; // Ensure a search string has been specified. if (text.Length > 0) { // Obtain the location of the search string in richTextBox1. int indexToText = richTextBox1.Find(text); // Determine whether the text was found in richTextBox1. if(indexToText >= 0) { returnValue = true; } } return returnValue; } mahes

        A 1 Reply Last reply
        0
        • M maheswara

          public bool FindMyText(string text) { // Initialize the return value to false by default. bool returnValue = false; // Ensure a search string has been specified. if (text.Length > 0) { // Obtain the location of the search string in richTextBox1. int indexToText = richTextBox1.Find(text); // Determine whether the text was found in richTextBox1. if(indexToText >= 0) { returnValue = true; } } return returnValue; } mahes

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          thnkz..i got solution!!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups