如何通过C#获取一个字符串如--user-data-dir=CChromeUserData --win-jumplist-action=most-visitedfileCPathToDatatxt的以file开头可能以空格结尾的SUBSTRING?
要获取一个以"file:///"开头,可能以空格结尾的子字符串,可以使用以下代码:
string input = @"user-data-dir=""C:\ChromeUserData"" --win-jumplist-action=most-visited:file:///C:\PathTo\Data.txt";
int startIndex = input.IndexOf("file:///");
int endIndex = input.LastIndexOf(" ");
string substring = input.Substring(startIndex, endIndex - startIndex);
这段代码首先使用IndexOf方法找到字符串中"file:///"的起始索引,然后使用LastIndexOf方法找到最后一个空格的索引。最后,使用Substring方法提取从起始索引到最后一个空格之间的子字符串。
注意:在这个例子中,使用了一个字符串变量input来表示输入的字符串。你需要根据你的实际情况修改这个变量的值
原文地址: http://www.cveoy.top/t/topic/iohb 著作权归作者所有。请勿转载和采集!