GetFileNameUtility.cs 534 B

12345678910111213141516171819202122
  1. using System;
  2. using Blue;
  3. public class GetFileNameUtility : IUtility
  4. {
  5. private string fileName="";
  6. public string GetFileName(string url,string fileType)
  7. {
  8. int index = url.IndexOf(fileType);
  9. if(index<0) throw new Exception("URL下载链接或者文件类型不规范");
  10. for(int i= index; i>0; i-- )
  11. {
  12. if(url[i]=='/')
  13. {
  14. fileName = url.Substring(i+1,index-i-1)+fileType;
  15. break;
  16. }
  17. }
  18. return fileName;
  19. }
  20. }