Posts

Showing posts with the label compare

C# Method to Compare DateTime Fields Specified During Execution?

C# Method to Compare DateTime Fields Specified During Execution? My project has many objects with date fields, and I often need to select everything where one such field is within a date range. For example: public class Contract { public DateTime SignDate { get; set; } public DateTime ReleaseDate { get; set; } } public class PersonalCheck { public DateTime SignDate { get; set; } public DateTime ProcessDate { get; set; } public DateTime VoidDate { get; set; } } If I only cared about SignDate, it would be easy. I would declare an Interface... public interface IObjectWithSignDate { DateTime SignDate { get; set; } } ...change my other objects to inherit from it, then create a method like this: public static IQueryable<T> SignedWithin<T>(this IQueryable<T> items, DateTime start, DateTime end) where T : IObjectWithSignDate { return items.Where(q => q.SignDate >= start && q.SignDate <= end); } How can I avoid rewr...

python difflib print only matches part between two strings

python difflib print only matches part between two strings I am totally new with python, and I need some help about difflib. I tried read the documentation, but for me is not easy to understand the docs. I would like compare two strings, and I want the output is only the matches prefix-part between two string (do not print the differences) . Example: t1 = "hello my name is Tom" t2 = "hello his name is Sawyer" expected output is: "hello " I tried by following approaches, but the output is not what I want because it print the output as array and also print not only matches part: #!/usr/bin/python import difflib t1 = "hello my name is Tom" t2 = "hello his name is Sawyer" seq = difflib.Differ() seq = seq.compare(t1,t2) print list(seq) other example-2: t1 = "20180628-153020" t2 = "20180628-173020" expected output printout: "20180628-1" and the suffix "3020" even both part of string matches the position...