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. C# string need to search for a lack of < & >

C# string need to search for a lack of < & >

Scheduled Pinned Locked Moved C#
csharpquestion
5 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.
  • G Offline
    G Offline
    glennPattonWork3
    wrote on last edited by
    #1

    Hi All, Question I have a string of Data that I am going to split with the method :

    string[] Values = FileData.Split(delimeterCharFurther);

    delimeterCharFurther are

    char[] delimeterCharFurther = { '<', '>' };

    I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable

    for (int a = 0; a <= FileData.Length; a++)
    {
    Location = FileData.IndexOf("><");
    MessageBox.Show(Location.ToString());

    }

    but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following

    L D P 3 Replies Last reply
    0
    • G glennPattonWork3

      Hi All, Question I have a string of Data that I am going to split with the method :

      string[] Values = FileData.Split(delimeterCharFurther);

      delimeterCharFurther are

      char[] delimeterCharFurther = { '<', '>' };

      I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable

      for (int a = 0; a <= FileData.Length; a++)
      {
      Location = FileData.IndexOf("><");
      MessageBox.Show(Location.ToString());

      }

      but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      IndexOf is overloaded, therefore location=string.IndexOf(subString, location+1); if often used in a loop for such purposes. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      1 Reply Last reply
      0
      • G glennPattonWork3

        Hi All, Question I have a string of Data that I am going to split with the method :

        string[] Values = FileData.Split(delimeterCharFurther);

        delimeterCharFurther are

        char[] delimeterCharFurther = { '<', '>' };

        I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable

        for (int a = 0; a <= FileData.Length; a++)
        {
        Location = FileData.IndexOf("><");
        MessageBox.Show(Location.ToString());

        }

        but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following

        D Offline
        D Offline
        DonDiegoDeLaVega
        wrote on last edited by
        #3

        Hi Glenn, Not sure what 'valid' means : what about "<a<b>>" ?? you should get "a","b" If so 'split' is probably not the path to the solution. But if not (i.e. <a<b>> is invalid ) why not

        string[] Values = FileData.Split('<');

        first then check values that are ending with a '>' Regards

        G 1 Reply Last reply
        0
        • D DonDiegoDeLaVega

          Hi Glenn, Not sure what 'valid' means : what about "<a<b>>" ?? you should get "a","b" If so 'split' is probably not the path to the solution. But if not (i.e. <a<b>> is invalid ) why not

          string[] Values = FileData.Split('<');

          first then check values that are ending with a '>' Regards

          G Offline
          G Offline
          glennPattonWork3
          wrote on last edited by
          #4

          Thanks for that, I think 'valid' was my typing as thinking the data is (should be) enclosed in < & > but in transmission some times it shows up as Data not (or even D!"" random ASCII) if it does throw 'em away and carry on. My think was along the lines of declare an int pointer increment over the string, then I remembered it was Windows and C#, not DOS & Turbo C!! Glenn

          1 Reply Last reply
          0
          • G glennPattonWork3

            Hi All, Question I have a string of Data that I am going to split with the method :

            string[] Values = FileData.Split(delimeterCharFurther);

            delimeterCharFurther are

            char[] delimeterCharFurther = { '<', '>' };

            I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable

            for (int a = 0; a <= FileData.Length; a++)
            {
            Location = FileData.IndexOf("><");
            MessageBox.Show(Location.ToString());

            }

            but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Or use a Regular Expression: @"<(?'Data'[^>]*?>"

            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