Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C#中的以下字符串分析命令行?_C# - Fatal编程技术网

从C#中的以下字符串分析命令行?

从C#中的以下字符串分析命令行?,c#,C#,我有以下格式的字符串: httP;//whatvere[CanIncludeSpaces"].url -a -b -c 如何获取字符串数组中的参数-a、-b、-c 谢谢以下是我的想法: var str = "httP;//whatvere[CanIncludeSpaces\"].url -a -b -c"; var endOfUrl = str.LastIndexOf(".url") + 4; var args = str.Substring(endOfUrl).Split(new[]{' '

我有以下格式的字符串:

httP;//whatvere[CanIncludeSpaces"].url -a -b -c
如何获取字符串数组中的参数-a、-b、-c


谢谢

以下是我的想法:

var str = "httP;//whatvere[CanIncludeSpaces\"].url -a -b -c";
var endOfUrl = str.LastIndexOf(".url") + 4;
var args = str.Substring(endOfUrl).Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
//args is ["-a", "-b", "-c"]
//also, the URL is easy to get:
var url = str.Substring(0, endOfUrl);
//url is now 'httP;//whatvere[CanIncludeSpaces"].url'

这些字符串应该代表实际的超链接吗?或者,您发布的示例似乎类似于超链接,这只是巧合吗?不,第一部分是url,参数是常规参数。可以包含空格部分由[]分隔?您可以使用正则表达式获取它…您只需反转字符串,在空格上拆分,循环遍历字符串,当遇到第一个不以破折号(-)开头的字符串时停止,因为每个参数(根据您的示例)前面都有破折号,并且它们都将位于末尾。