Assume that you have a short list that defines the value (e.g., AB1, D2, CC3 ) And you get a string value (e.g., "happy: DE2 | 234") to see if a short word is found in the string. For a small list of acquaintances I would usually create a simple regx that used a separator (ex. (AB1 | DE2 | CC3)) and just look for a match.
But if I have to match against more than 30 acquaintances, how will I face it? Does it mean to use the same technique (ugly) or is there a more effective and elegant way to accomplish this task?
Remember the example introductory list and the example string is not the actual data format. I am working together instead of conveying my challenge.
BTW, I have read one, but I do not think I am trying to fulfill it.
EDIT: I forgot to include my requirement to capture the matched value, so the option to use regular expressions ...
var acronyms = new [] {"AB", "BC", "CD", "ZZAB"}; Var regex = new Regex (string.Join ("|", acronyms), RegexOptions.Compiled); Match (match = regex.Match ("ZZZABCDZZZ"); Match. Success; Match = Match. Next Match ()) Console. Match line (match value); // Return AB and CD
Then code is relatively elegant and maintenance. If you know that the number of latitudes is upper bound, then I have to do some tests, who knows how the adaptation has already been created in the reggae engine, enable you to profit from future regex engine optimization Will be Unless you have a belief that performance is a problem, it will be easy.
On the other hand, there may be other limitations on regex eg. By default if you have acronyms AB, BC and CD then it will return only two of these as a match in "ABCD". So it is good to tell you that there is a short name but you need to be careful about catching many matches.
When the demonstration became an issue for me (> 10,000 items) I searched the 'Exceram' in a hash, then search for each substrings of text (from minimum acronym length to maximum duration length). It was okay for me because the source text was too small I had not heard of it before, but for the first time, look at the Aho-Corsec algorithm, which you have referred to in context, seems like a better general solution to this problem.
Comments
Post a Comment