Posted By

manatlan on 09/14/09


Tagged

regex text DateTime csharp


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

rageit
khouser
danfinrud55


C# tricks : regex, encoding, log, format date


 / Published in: C#
 

  1. //==========================================
  2. // REGEX
  3. //==========================================
  4. using System.Text.RegularExpressions;
  5.  
  6. Regex r = new Regex(@"CES=([^,]+),");
  7. Match m = r.Match(rf);
  8. if (m.Success)
  9. rf = m.Groups[1].Value;
  10. else
  11. rf = "";
  12.  
  13. //==========================================
  14. // TEXT ENCODING (utf8 -> cp1252)
  15. //==========================================
  16. csv = Encoding.GetEncoding("Windows-1250").GetString(Encoding.UTF8.GetBytes( csv ) );
  17.  
  18. //==========================================
  19. // MAKE A QUICK LOG
  20. //==========================================
  21. private void log(object o)
  22. {
  23. System.IO.File.AppendAllText("C:/Temp/logmarco4.txt", "-" + Convert.ToString(o)+"\n");
  24. }
  25.  
  26. //==========================================
  27. // FORMAT Date
  28. //==========================================
  29. String.Format("{0:d/M/yyyy HH:mm:ss}", dt); // "9/3/2008 16:05:07"

Report this snippet  

You need to login to post a comment.