Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static string ArrayToString(string[] arr)
- {
- StringBuilder builder = new StringBuilder();
- foreach(string str in arr)
- {
- builder.Append(str);
- }
- return builder.ToString();
- }
- static string LongestMatch(string[] book1, string[] book2)
- {
- string longestMatch = "";
- string current = "";
- string text1 = ArrayToString(book1);
- string text2 = ArrayToString(book2);
- int startId = 0;
- for (int i = startId; i < text1.Length; i++)
- {
- current += text1[i];
- if(Regex.Match(text2,@current).Success && longestMatch.Length < current.Length)
- {
- longestMatch = current;
- }
- else if(!Regex.Match(text2, @current).Success)
- {
- current = "";
- startId++;
- i = startId;
- }
- }
- return longestMatch;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement