程序中应包含如下URI:
rtsp://127.0.0.1:554/live.sdp/
rtsp://127.0.0.1:554/live.sdp
rtsp://127.0.0.1:554
rtsp://127.0.0.1:554/
rtsp://127.0.0.1:554//live.sdp
最后,我只希望有一种干净的方法:
rtsp://127.0.0.1:554/live.sdp
其中方案(rtsp://)、ip (127.0.0.1)、端口(554)和路径(live.sdp)分别提交。所以我必须确保路径不只包含斜杠(/),不以斜杠(/live.sdp)开头,不以斜杠结束(live.sdp/),也不以斜杠结尾(rtsp://127.0.0.1:554/),这样我就可以在URL和路径之间添加一个斜杠,而不用担心会出问题。
有什么简单的方法可以做到这一点吗?
发布于 2013-01-03 13:19:33
使用UriBuilder类解析和构造URI。没有必要重新发明轮子。
发布于 2013-01-03 13:27:11
使用string split and format
尝试一下;
string s1 = ip + ":" + port + "/" + path;
string[] arr = s1.Split(new string[] { "/" },
StringSplitOptions.RemoveEmptyEntries);
string url = scheme + string.Format("{0}/{1}", arr)
发布于 2013-01-03 13:36:11
试试这样的东西
var uri = new UriBuilder(String.Format("{0}://{1}:{2}/{3}",protocol,host,port,path)).Uri;
https://stackoverflow.com/questions/14139385
复制相似问题