Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. keywords=>cat,dog
  2. text=> a catchy cat with a dogged dog
  3.  
  4. var results= keywords.Select(x=>
  5. new
  6. {
  7. word=x,
  8. indexes=Regex.Matches(input,@"b"+x+@"b")
  9. .Cast<Match>().Select(y=>y.Index)
  10. .ToList()
  11. }
  12. );
  13.  
  14. foreach(var match in results)
  15. {
  16. match.word;
  17. foreach(int index in match.indexes)//index
  18. }
  19.  
  20. private List<int> GetIndexForKeyWord(string content,string key)
  21. {
  22. int index = 0;
  23. List<int> indexes=new List<int>();
  24. while (index < content.Length && index >= 0)
  25. {
  26. index = content.IndexOf(key, index);
  27. if (index+key.Length==content.Length||index >= 0 && !char.IsLetter(content[index + key.Length]))
  28. {
  29. indexes.Add(index);
  30. }
  31. if(index!=-1)
  32. index++;
  33. }
  34. return indexes;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement