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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Search and Retrieving String

Search and Retrieving String

Scheduled Pinned Locked Moved C#
tutorialquestion
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.
  • A Offline
    A Offline
    ASPnoob
    wrote on last edited by
    #1

    Hi all, suppose I have a text file that contains hundreds of entries with each entry surrounded by an opening @ symbol and a closing /@ symbol, and each entry is separated from the next by a blank line like below:

    @ Entry Date: 6/01/2014, Time:1000 AM EST, UserID: U123456789,

    Input: Blah Blah Blah ggogo klj'm' lkkjhgy 8oiui9in lrxutxcuucx cufcfx rdutrrrd dxddzsz, /@

    @ Entry Date: 7/01/2014, Time:1000 AM EST, UserID: U134233569,

    Input: tgvggv jjjn tsewa klj'm' lkkjhgy ojgi yvytf j;jn ij[ji tfzdy , /@

    If I want to get all the inputs of a particular user with a certain UserID, how would I go about doing that? I know I have to use string.contain method to check if a certain UserID exist and if it does, use the characters "@", "/@", "Input:", and "," as the delimiters to refine the search. But I'm not real clear on how to go about it. Any suggestions will be greatly appreciated, thanks in advance.

    M V E 3 Replies Last reply
    0
    • A ASPnoob

      Hi all, suppose I have a text file that contains hundreds of entries with each entry surrounded by an opening @ symbol and a closing /@ symbol, and each entry is separated from the next by a blank line like below:

      @ Entry Date: 6/01/2014, Time:1000 AM EST, UserID: U123456789,

      Input: Blah Blah Blah ggogo klj'm' lkkjhgy 8oiui9in lrxutxcuucx cufcfx rdutrrrd dxddzsz, /@

      @ Entry Date: 7/01/2014, Time:1000 AM EST, UserID: U134233569,

      Input: tgvggv jjjn tsewa klj'm' lkkjhgy ojgi yvytf j;jn ij[ji tfzdy , /@

      If I want to get all the inputs of a particular user with a certain UserID, how would I go about doing that? I know I have to use string.contain method to check if a certain UserID exist and if it does, use the characters "@", "/@", "Input:", and "," as the delimiters to refine the search. But I'm not real clear on how to go about it. Any suggestions will be greatly appreciated, thanks in advance.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I would create an object that will hold all the bits of your info, Depending on the size of the file I would either read it all into memory or read it 1 line at a time. If the line starts with your open token @ set a flag, keep reading till your line ends with your end token /@, appending the line(s) to a string variable. Depending on your structure I would then pass the string variable to a parser which chops up the crap you are getting for data, it looks like the start of the record is reasonable and it deteriorates into rubbish with no structure. The parser should return an instance of the object which is then added to a List<>. Repeat until you get to the end of the file.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • A ASPnoob

        Hi all, suppose I have a text file that contains hundreds of entries with each entry surrounded by an opening @ symbol and a closing /@ symbol, and each entry is separated from the next by a blank line like below:

        @ Entry Date: 6/01/2014, Time:1000 AM EST, UserID: U123456789,

        Input: Blah Blah Blah ggogo klj'm' lkkjhgy 8oiui9in lrxutxcuucx cufcfx rdutrrrd dxddzsz, /@

        @ Entry Date: 7/01/2014, Time:1000 AM EST, UserID: U134233569,

        Input: tgvggv jjjn tsewa klj'm' lkkjhgy ojgi yvytf j;jn ij[ji tfzdy , /@

        If I want to get all the inputs of a particular user with a certain UserID, how would I go about doing that? I know I have to use string.contain method to check if a certain UserID exist and if it does, use the characters "@", "/@", "Input:", and "," as the delimiters to refine the search. But I'm not real clear on how to go about it. Any suggestions will be greatly appreciated, thanks in advance.

        V Offline
        V Offline
        V 0
        wrote on last edited by
        #3

        I'm with Mycroft Holmes. You need an object eg Entry with several properties: * entrydate * userid * input * ... Then read in the file. You have several options: read line per line or in one piece and then split. If there are more then one message per userid you can more cleverly make a dictionary holding all the data for that user... Hope this gives you some ideas.

        V.
        (MQOTD rules and previous solutions)

        1 Reply Last reply
        0
        • A ASPnoob

          Hi all, suppose I have a text file that contains hundreds of entries with each entry surrounded by an opening @ symbol and a closing /@ symbol, and each entry is separated from the next by a blank line like below:

          @ Entry Date: 6/01/2014, Time:1000 AM EST, UserID: U123456789,

          Input: Blah Blah Blah ggogo klj'm' lkkjhgy 8oiui9in lrxutxcuucx cufcfx rdutrrrd dxddzsz, /@

          @ Entry Date: 7/01/2014, Time:1000 AM EST, UserID: U134233569,

          Input: tgvggv jjjn tsewa klj'm' lkkjhgy ojgi yvytf j;jn ij[ji tfzdy , /@

          If I want to get all the inputs of a particular user with a certain UserID, how would I go about doing that? I know I have to use string.contain method to check if a certain UserID exist and if it does, use the characters "@", "/@", "Input:", and "," as the delimiters to refine the search. But I'm not real clear on how to go about it. Any suggestions will be greatly appreciated, thanks in advance.

          E Offline
          E Offline
          Emre Ataseven
          wrote on last edited by
          #4

          First get all matches between @ and /@ tags, then write a method which takes a single block and returns UserID (you can do it by indexof and substring methods) then iterate all matches and take appropriate ids. So;

          MatchCollection matchList = Regex.Matches(yourInput, yourPattern);
          var list = matchList.Cast<Match>().Select(match => match.Value).ToList();

          //Filter list
          var result = list.Where(p=> GetUserID(p) == "XXXXX").ToList();

          private string GetUserID(string singleBlock)
          {
          Extract user id and return it;
          }

          Tim Toady Bicarbonate

          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