【发布时间】:2014-05-22 10:32:42
【问题描述】:
我是 C# 的初学者,我只想从这样的字符串中提取 "title" 字符串:"http://playdebug.games.com/facebook/title.html"
【问题讨论】:
-
伙计们。该人刚刚给出了一个获取 URL 的 title 部分的示例。你要找的是 HERE
我是 C# 的初学者,我只想从这样的字符串中提取 "title" 字符串:"http://playdebug.games.com/facebook/title.html"
【问题讨论】:
我建议使用Path.GetFileNameWithoutExtension()
String toParse = "http://playdebug.games.com/facebook/title.html";
String result = Path.GetFileNameWithoutExtension(toParse);
【讨论】:
Path 只允许文件系统路径,而不是 URI。
只需通过子字符串获取最后一部分,要剪切的位置是'/'的最后一个索引。 字符串 s = "http://playdebug.games.com/facebook/title.html";
s = s.Substring(s.LastIndexOf('/') + 1);
或短途,因为它可以被视为一条路径;)
string s = Path.GetFileNameWithoutExtension("http://playdebug.games.com/facebook/title.html");
【讨论】: