Extracting date and time from text using Ruby

Problem: We want to extract a date and time of the format YYYY-MM-DD MM:SS from a body of text using Ruby. Solution: This is extremely easy in ruby, and other languages that features regular expressions. require “Date” text = “Some text containing a date and a time, for instance 2010-03-19 17:25.” if text =~ /(\d{4})-(\d{2})-(\d{2}) […]

Adding Linebreaks in C#

Problem: We want to insert linebreak character sequences into a string in C#.  Solution: The platform safe way of doing this is by using the Environment.NewLine property. msg = “An error occurred: ” + Environment.NewLine + e.Message; Composing a string with more than one line break can become really messy, so using string.Format might be a […]