Tools.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. namespace AVSORTER
  8. {
  9. public class Tools
  10. {
  11. public static string Fcode(string code)
  12. {
  13. Regex r1 = new Regex(@"(\d{0,1}[a-zA-Z]{2,5})[- _]{0,1}(\d{2,5})");
  14. if (r1.Match(code).Value=="")
  15. {
  16. return code;
  17. }
  18. var c = r1.Match(code).Groups[1].Value;
  19. var n = r1.Match(code).Groups[2].Value;
  20. return (c + "-" + n).ToUpper();
  21. }
  22. public static string ListToString(IEnumerable<string> list)
  23. {
  24. if (list.Count()==0)
  25. {
  26. return string.Empty;
  27. }
  28. StringBuilder sb = new StringBuilder();
  29. foreach (string item in list)
  30. {
  31. sb.Append(item);
  32. sb.Append(",");
  33. }
  34. sb.Remove(sb.Length - 1, 1);
  35. return sb.ToString();
  36. }
  37. public static string RemoveInvalidChars(string Title)
  38. {
  39. var ichr = Path.GetInvalidPathChars();
  40. foreach (var item in ichr)
  41. {
  42. Title = Title.Replace(item, '_');
  43. }
  44. ichr = Path.GetInvalidFileNameChars();
  45. foreach (var item in ichr)
  46. {
  47. Title = Title.Replace(item, '_');
  48. }
  49. return Title;
  50. }
  51. }
  52. }