UrlTool.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Azylee.Core.DataUtils.CollectionUtils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Azylee.Core.DataUtils.StringUtils
  7. {
  8. public class UrlTool
  9. {
  10. /// <summary>
  11. /// 连接多个string构成url
  12. /// </summary>
  13. /// <param name="paths"></param>
  14. /// <returns></returns>
  15. public static string Combine(params string[] paths)
  16. {
  17. if (ListTool.HasElements(paths))
  18. {
  19. if (paths.Length > 1)
  20. {
  21. StringBuilder result = new StringBuilder(paths[0]);
  22. for (int i = 1; i < paths.Length; i++)
  23. {
  24. if (paths[i] != null)
  25. {
  26. string u = paths[i];
  27. if (u.StartsWith("/")) u = u.Substring(1);
  28. if (!result.ToString().EndsWith("/")) result.Append("/");
  29. result.Append(u);
  30. }
  31. }
  32. return result.ToString();
  33. }
  34. else
  35. {
  36. return paths[0];
  37. }
  38. }
  39. return "";
  40. }
  41. }
  42. }