gpt4 book ai didi

c# - 解析变量 URI (RegEx, Uri, String-Functions?) c#

转载 作者:行者123 更新时间:2023-12-04 05:35:15 25 4
gpt4 key购买 nike

我正在编写一个 RTSP 客户端模块,为此,我需要解析一个非常可变的 URI。但我完全不知道应该使用哪种方法(最安全)以及如何实现这一点。

示例 URI 可能如下所示:

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

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

谢谢你。

最佳答案

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();

关于c# - 解析变量 URI (RegEx, Uri, String-Functions?) c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12036958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com