Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. static string ArrayToString(string[] arr)
  2. {
  3. StringBuilder builder = new StringBuilder();
  4. foreach(string str in arr)
  5. {
  6. builder.Append(str);
  7. }
  8.  
  9. return builder.ToString();
  10. }
  11.  
  12. static string LongestMatch(string[] book1, string[] book2)
  13. {
  14.  
  15. string longestMatch = "";
  16. string current = "";
  17. string text1 = ArrayToString(book1);
  18. string text2 = ArrayToString(book2);
  19.  
  20. int startId = 0;
  21.  
  22. for (int i = startId; i < text1.Length; i++)
  23. {
  24. current += text1[i];
  25. if(Regex.Match(text2,@current).Success && longestMatch.Length < current.Length)
  26. {
  27. longestMatch = current;
  28. }
  29. else if(!Regex.Match(text2, @current).Success)
  30. {
  31. current = "";
  32. startId++;
  33. i = startId;
  34. }
  35. }
  36.  
  37. return longestMatch;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement