Search and Retrieving String
-
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.
-
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.
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
-
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.
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) -
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.
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