Skip to content

Commit 47061af

Browse files
author
fengyunhai
committed
新增:URL分析(Host/Path/File/Query分拆)
1 parent 206da3a commit 47061af

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Qiniu/Fusion/Model/UrlHelper.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,26 @@ public static string GetNormalUrl(string _url)
3131
return m.Value;
3232
}
3333

34+
public static void UrlSplit(string url, out string host, out string path, out string file, out string query)
35+
{
36+
int start = 0;
37+
38+
Regex regHost = new Regex(@"(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+");
39+
host = regHost.Match(url, start).Value;
40+
start += host.Length;
41+
42+
Regex regPath = new Regex(@"(/(\w|\-)*)+/");
43+
path = regPath.Match(url, start).Value;
44+
if(string.IsNullOrEmpty(path))
45+
{
46+
path = "/";
47+
}
48+
start += path.Length;
49+
50+
int index = url.IndexOf('?', start);
51+
file = url.Substring(start, index - start);
52+
53+
query = url.Substring(index);
54+
}
3455
}
3556
}

0 commit comments

Comments
 (0)