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. Searching the inbetweens?

Searching the inbetweens?

Scheduled Pinned Locked Moved C#
questioncomalgorithmshelp
5 Posts 3 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.
  • J Offline
    J Offline
    jas0n23
    wrote on last edited by
    #1

    Hi all!, I have a weird question and some code that isn't quite right. :( I am creating a personal project where I have an already-existing text file which consists of mainly symbols and standard text as follows: Sample Text File contents: http://www.my_soon-to-be_homepage.com.au/ This file may contain X number of lines, and what I am trying to do is search for the in-betweens, what I mean by that is I want to be able to search for the keywords (human, being, person, hairy, funny, intelligent etc..) that are inbetween the symbols and then put those found keywords into a string so that i can cut, copy, paste, change them at my own will. Then I need to be able to search for a URL that is within that same text file. And then put that URL into a string so I can cut, copy, paste etc..... into a textBox. I have some code here that searches but it doesn't work the way i want it to. I'd appreciate any samps, tutorials, advice/ or ANY help i can get from anybody. Thanks for taking the time to read this. I hope it wasn't too confusing.. :-D best regards, j.t. j.t.

    E S 2 Replies Last reply
    0
    • J jas0n23

      Hi all!, I have a weird question and some code that isn't quite right. :( I am creating a personal project where I have an already-existing text file which consists of mainly symbols and standard text as follows: Sample Text File contents: http://www.my_soon-to-be_homepage.com.au/ This file may contain X number of lines, and what I am trying to do is search for the in-betweens, what I mean by that is I want to be able to search for the keywords (human, being, person, hairy, funny, intelligent etc..) that are inbetween the symbols and then put those found keywords into a string so that i can cut, copy, paste, change them at my own will. Then I need to be able to search for a URL that is within that same text file. And then put that URL into a string so I can cut, copy, paste etc..... into a textBox. I have some code here that searches but it doesn't work the way i want it to. I'd appreciate any samps, tutorials, advice/ or ANY help i can get from anybody. Thanks for taking the time to read this. I hope it wasn't too confusing.. :-D best regards, j.t. j.t.

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      If you make your file XML you can use an XML reader to access the attribute values. (The values in quotes)

      Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
      Most of this sig is for Google, not ego.

      1 Reply Last reply
      0
      • J jas0n23

        Hi all!, I have a weird question and some code that isn't quite right. :( I am creating a personal project where I have an already-existing text file which consists of mainly symbols and standard text as follows: Sample Text File contents: http://www.my_soon-to-be_homepage.com.au/ This file may contain X number of lines, and what I am trying to do is search for the in-betweens, what I mean by that is I want to be able to search for the keywords (human, being, person, hairy, funny, intelligent etc..) that are inbetween the symbols and then put those found keywords into a string so that i can cut, copy, paste, change them at my own will. Then I need to be able to search for a URL that is within that same text file. And then put that URL into a string so I can cut, copy, paste etc..... into a textBox. I have some code here that searches but it doesn't work the way i want it to. I'd appreciate any samps, tutorials, advice/ or ANY help i can get from anybody. Thanks for taking the time to read this. I hope it wasn't too confusing.. :-D best regards, j.t. j.t.

        S Offline
        S Offline
        sph3rex
        wrote on last edited by
        #3

        Either use the System.XML namespace thus formatting your document to use XML standard formatting, either use the System.Text.RegularExpressions namespace similar to: System.Net.RegularExpressions reg = new System.Net.RegularExpressions.Regex("<[a-z]+=""([a-z,\s]+)"" \/>"); Use expresso to get the expression that best fits ur needs. The above is just a shallow example.

        J 1 Reply Last reply
        0
        • S sph3rex

          Either use the System.XML namespace thus formatting your document to use XML standard formatting, either use the System.Text.RegularExpressions namespace similar to: System.Net.RegularExpressions reg = new System.Net.RegularExpressions.Regex("<[a-z]+=""([a-z,\s]+)"" \/>"); Use expresso to get the expression that best fits ur needs. The above is just a shallow example.

          J Offline
          J Offline
          jas0n23
          wrote on last edited by
          #4

          Oh, sorry, I forgot to post the code I mentioned in my Question. Thanks for helping me, both of you :-) It's much appreciated:

          using System.IO;
          using System.Text.RegularExpressions;

              private void SearchLink\_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
              {
                  if( File.Exists("C:\\\\Users\\\\Jase\\\\Desktop\\\\Test.txt"))
                  {
                  // File to search.
                  string FileName = "C:\\\\Users\\\\Jase\\\\Desktop\\\\Test.txt";
          
                  // Reads file to end.
                  StreamReader SearchText = new StreamReader(FileName);
                  string ReadAll = SearchText.ReadToEnd();
          
                  // SearchTextBox.Text contains string to search for.
                  SearchText.Close();
                  string regMatch = SearchTextBox.Text;
          
                  // If the string has been found, do something.
                  if (Regex.IsMatch(ReadAll, regMatch))
                  {
                      MessageBox.Show("Found\\n" + "" + regMatch);
                  }
                  else
                  {
                      MessageBox.Show("Not found\\n");
                  }
                  }
                  else
                  {
                      MessageBox.Show("Non-Existant File.");
                  }
              }
          

          The only problem with this code is it requires somebody to enter text into a textbox and then it will search for that text in an existing file. I actually need to just search for anything that is inbetween two quotes ("sample thing"). I tried both of your suggestions and I got a little confused and it didn't work, so I went to MSDN before posting another question here and I left MSDN even more confused. Thanks for your quick replies :-)

          j.t.

          S 1 Reply Last reply
          0
          • J jas0n23

            Oh, sorry, I forgot to post the code I mentioned in my Question. Thanks for helping me, both of you :-) It's much appreciated:

            using System.IO;
            using System.Text.RegularExpressions;

                private void SearchLink\_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
                {
                    if( File.Exists("C:\\\\Users\\\\Jase\\\\Desktop\\\\Test.txt"))
                    {
                    // File to search.
                    string FileName = "C:\\\\Users\\\\Jase\\\\Desktop\\\\Test.txt";
            
                    // Reads file to end.
                    StreamReader SearchText = new StreamReader(FileName);
                    string ReadAll = SearchText.ReadToEnd();
            
                    // SearchTextBox.Text contains string to search for.
                    SearchText.Close();
                    string regMatch = SearchTextBox.Text;
            
                    // If the string has been found, do something.
                    if (Regex.IsMatch(ReadAll, regMatch))
                    {
                        MessageBox.Show("Found\\n" + "" + regMatch);
                    }
                    else
                    {
                        MessageBox.Show("Not found\\n");
                    }
                    }
                    else
                    {
                        MessageBox.Show("Non-Existant File.");
                    }
                }
            

            The only problem with this code is it requires somebody to enter text into a textbox and then it will search for that text in an existing file. I actually need to just search for anything that is inbetween two quotes ("sample thing"). I tried both of your suggestions and I got a little confused and it didn't work, so I went to MSDN before posting another question here and I left MSDN even more confused. Thanks for your quick replies :-)

            j.t.

            S Offline
            S Offline
            sph3rex
            wrote on last edited by
            #5

            IsMatch returns a boolean whether it found or not your regex expression in the input string. The correct way to use regex would be with this basic regex Regex reg = New Regex("""(.+?)""", RegexOptions.IgnoreCase | RegexOptions.Multiline); MatchCollection mtc = reg.Matches("input string"); this will return a MatchCollection which u can loop through to get every match of the pattern in the input string. Use the GetEnumerator method of the above MatchCollection to loop through the matches.

            Code? Yeah i love it fried together with a glass of wine.

            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