Formatter.cs 795 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. namespace BeatLyrics.Tool.Utils
  5. {
  6. internal static class Formatter
  7. {
  8. public static string FormatToTotalMinuteAndSeconds(this TimeSpan d) => $"{Math.Floor(d.TotalMinutes):00}:{d.Seconds:00}";
  9. public static string FormatToTotalMinuteAndSecondsAndMs(this TimeSpan d) => $"{Math.Floor(d.TotalMinutes):00}:{d.Seconds:00}.{d.Milliseconds:000}";
  10. public static string ToSafeFileName(this string str)
  11. {
  12. var inv = Path.GetInvalidFileNameChars();
  13. var chars = str.ToCharArray();
  14. for (var i = 0; i < chars.Length; i++)
  15. {
  16. if (inv.Contains(chars[i])) chars[i] = '_';
  17. }
  18. return new string(chars);
  19. }
  20. }
  21. }