解析变量URI(RegEx,Uri,字符串函数?)c# [英] Parse variable URI (RegEx, Uri, String-Functions?) c#

查看:129
本文介绍了解析变量URI(RegEx,Uri,字符串函数?)c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写RTSP客户端模块,为此,我需要解析一个非常可变的URI.但是我对应该使用哪种方法(大多数故障保护)以及如何实现这一目标完全感到困惑.

I'm writing a RTSP client module and for this, I need to parse an very variable URI. But I'm completely stuck about which method I should use (most-failsafe) and how to accomplish this.

示例URI可能如下所示:

An example URI could look like this:

rtsp://192.168.1.100:554/videocam/media/1/video/1
\_/    \_______________/\_______/\______________/
 |              |           |           |
scheme      authority     [sub]     [mediacontrol]

还有其他可能性:

192.168.1.100/videocam/media/1/video/1
192.168.1.100:6000/media/1/video/1
192.168.1.100:6000/videocam

我需要以下信息:

IP         | how can I recognise this pattern [num].[num].[num].[num]?
Port       | easy if the string contains rtsp://, but what about just a number? 1-65555
Sub        | Optional subpath, can completely vary!
MediaLevel | Optional MediaLevel (indicator for stream/track), 
             not to be confused with the path. MediaLevel can be also just like this: track1 or m1s3 or media1/video1.. see?
             I can't go for the slash, also the path also can contain multiple slashes

也许有一个用于执行此类任务的库?

Maybe there's a library for such tasks?

谢谢.

推荐答案

var uri = new Uri("rtsp://192.168.1.100:554/videocam/media/1/video/1");
var host = uri.Host;
var port = uri.Port;
var sub = uri.Segments[1];
var mlevel = uri.Segments.Skip(2).ToArray();

这篇关于解析变量URI(RegEx,Uri,字符串函数?)c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆