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. string searching??

string searching??

Scheduled Pinned Locked Moved C#
csharphtmlalgorithmshelptutorial
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.
  • S Offline
    S Offline
    Small Rat
    wrote on last edited by
    #1

    I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!

    Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

    S P P 3 Replies Last reply
    0
    • S Small Rat

      I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!

      Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

      S Offline
      S Offline
      Skippums
      wrote on last edited by
      #2

      Do the following, where 'keyword' is the search string (must have length of at least 2 characters)and 'str' is the file string:

      bool inAsp = false;
      bool inATag = false;
      List matches = new List();
      List curGuess = new List();
      for (int i = 0; i < str.Length; ++i) {
      char c = str.CharAt(i);
      if (inAsp) {
      if (EndingAspTag) // this is a pseudocode conditional
      inAsp = false;
      continue;
      } else if (inATag) {
      if (EndingATag) // this is a pseudocode conditional
      inATag = false;
      continue;
      } else if (StartingAspTag) { // this is a pseudocode conditional
      curGuess.Clear();
      inAsp = true;
      } else if (StartingATag) { // this is a pseudocode conditional
      curGuess.Clear();
      inATag = true;
      }
      for (int j = curGuess.Count - 1; j >= 0; --j) {
      if (c != keyword.CharAt(++curGuess[j]))
      curGuess.RemoveAt(j);
      else if (curGuess[j] == keyword.Length - 1) {
      matches.Add(i - curGuess[j]);
      curGuess.RemoveAt(j);
      }
      }
      if (c == keyword.CharAt(0))
      curGuess.Add(0);
      }
      for (int i = 1; i < matches.Count; ++i) {
      if (matches[i] - matches[i - 1] < keyword.Length)
      matches.RemoveAt(i--);
      }

      The code for the above conditions to check for entering or exiting an 'asp' or 'a' tag segment is non-trivial, as you also need to take into account whether you are within quotes, but you get the idea. This is also very inneficient, but it will work. Hope this helps,

      -Jeff

      1 Reply Last reply
      0
      • S Small Rat

        I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!

        Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

        P Offline
        P Offline
        pmarfleet
        wrote on last edited by
        #3

        Small Rat wrote:

        I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this??

        Have you attempted to solve the problem yourself? This site isn't for people who want their work done for them. There's plenty of resporces on Regular Expressions available on the web. Have you looked at any of them. BTW, I'm particularly surprised to see such behaviour from someone who claims to be Microsoft certified :suss:

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        1 Reply Last reply
        0
        • S Small Rat

          I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!

          Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Honestly. This is a C# forum. Do you really think you are going to get ASP help in this forum?

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          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