Guest User

Untitled

a guest
Jul 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. SELECT
  2. [titles].[title],
  3. [assets].[filename]
  4. FROM
  5. titles
  6. INNER JOIN
  7. assets ON titles.ID = assets.ID
  8. WHERE
  9. (title LIKE '%Life-Span%'
  10. AND title LIKE '%Development%'
  11. AND title LIKE '%16E%'
  12. AND title LIKE '%99%'
  13. AND title LIKE '%Subject%'
  14. AND title LIKE '%Index%')
  15.  
  16. static void Main(string[] args)
  17. {
  18. string searchText = "Life-Span Development 16E 99 Subject Index";
  19.  
  20. using (Entities db = new Entities())
  21. {
  22. var result = db.titles
  23. .Join(db.assets,
  24. p => p.tid,
  25. e => e.tid,
  26. (p, e) => new {
  27. title = p.title1,
  28. fileName = e.filename
  29. });
  30.  
  31. var searchTextArray = searchText.ToLower().Split(' ');
  32. result = result.Where(t => searchTextArray.Any(s => t.title.ToLower().Contains(s)));
  33.  
  34. foreach(var item in result)
  35. {
  36. Console.WriteLine(string.Format("Title = {0} and finename = {1}", item.title, item.fileName));
  37. }
  38. }
  39.  
  40. Console.ReadKey();
  41. }
  42.  
  43. namespace Like
  44. {
  45. class Program
  46. {
  47. static bool Is(char a, char b)
  48. {
  49. return a == b ||
  50. char.ToUpper(a) == b ||
  51. char.ToUpper(b) == a;
  52. }
  53. static bool IsLike(string sample, string query)
  54. {
  55. int k = 0;
  56. foreach (char c in sample)
  57. {
  58. if (!Is(c, query[k]))
  59. {
  60. k = 0;
  61. continue;
  62. }
  63. if (++k == query.Length)
  64. return true;
  65. }
  66. return false;
  67. }
  68.  
  69. static void Main(string[] args)
  70. {
  71. string testSample = "This is a str1ng 0f charac7er5";
  72. Console.WriteLine(IsLike(testSample, "this"));
  73. Console.WriteLine(IsLike(testSample, "of"));
  74. Console.WriteLine(IsLike(testSample, "chAra"));
  75. Console.ReadKey();
  76. }
  77. }
  78. }
Add Comment
Please, Sign In to add comment