【问题标题】:String Parsing using C# [duplicate]使用 C# 进行字符串解析 [重复]
【发布时间】:2014-05-22 10:32:42
【问题描述】:

我是 C# 的初学者,我只想从这样的字符串中提取 "title" 字符串:"http://playdebug.games.com/facebook/title.html"

【问题讨论】:

  • 伙计们。该人刚刚给出了一个获取 URL 的 title 部分的示例。你要找的是 HERE

标签: c# string


【解决方案1】:

我建议使用Path.GetFileNameWithoutExtension()

String toParse = "http://playdebug.games.com/facebook/title.html";
String result = Path.GetFileNameWithoutExtension(toParse);

【讨论】:

  • 我认为 Path 只允许文件系统路径,而不是 URI。
  • @OndrejTucny 不,它也适用于 URI。
  • @WasifHossain 很高兴知道,谢谢。
【解决方案2】:

只需通过子字符串获取最后一部分,要剪切的位置是'/'的最后一个索引。 字符串 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");

【讨论】:

    猜你喜欢
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多