Basic Search Query in C#


/ Published in: C#
Save to your folder(s)

Test 0: OK!
Test 1: OK!
Test 2: OK!
Test 3: Error: your code didn't finish in less than 2 seconds.
Test 4: Error: your code didn't finish in less than 2 seconds.
Test 5: Error: your code didn't finish in less than 2 seconds.


Copy this code and paste it in your HTML
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. class MyClass {
  5. public void search_query(string[] query, string[] pages) {
  6. // Write your code here.
  7. string tokensPattern =
  8. string.Format(".*{0}.*", string.Join(".*", query));
  9.  
  10. if(query.Length > 0)
  11. {
  12. int pageCount = 0;
  13.  
  14. foreach(string page in pages)
  15. {
  16. Match match = Regex.Match(page, tokensPattern);
  17.  
  18. if(match.Success)
  19. pageCount++;
  20. }
  21.  
  22. Console.WriteLine(pageCount.ToString());
  23. }
  24. }
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.