Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- keywords=>cat,dog
- text=> a catchy cat with a dogged dog
- var results= keywords.Select(x=>
- new
- {
- word=x,
- indexes=Regex.Matches(input,@"b"+x+@"b")
- .Cast<Match>().Select(y=>y.Index)
- .ToList()
- }
- );
- foreach(var match in results)
- {
- match.word;
- foreach(int index in match.indexes)//index
- }
- private List<int> GetIndexForKeyWord(string content,string key)
- {
- int index = 0;
- List<int> indexes=new List<int>();
- while (index < content.Length && index >= 0)
- {
- index = content.IndexOf(key, index);
- if (index+key.Length==content.Length||index >= 0 && !char.IsLetter(content[index + key.Length]))
- {
- indexes.Add(index);
- }
- if(index!=-1)
- index++;
- }
- return indexes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement