1

C#のみを使用してRocky44の中央の文字列が必要です

Hi <a href="http://example.com/index.php?action=profile"><span>Rocky44</span></a>

いくつかの分割方法を試しましたが、機能しません

string[] result = temp.Split(new string[] { "<a href=" + "http://example.com/index.php?action=profile" + "><span>" , "</span></a>" }, StringSplitOptions.RemoveEmptyEntries); 

例:

Hi <a href="http://example.com/index.php?action=profile"><span>Rocky44</span></a>

に:

Rocky44
4

4 に答える 4

0

メソッドを使用して<span>とのインデックスを見つけます。</span>IndexOf

次に ( の長さを調整して)メソッドを<span>使用して目的のテキストを取得します。String.Substring

string FindLinkText(string linkHtml)
{
    int startIndex = linkHtml.IndexOf("<span>") + "<span>".Length,
        length = linkHtml.IndexOf("</span>") - startIndex;

    return linkHtml.Substring(startIndex, length);
}
于 2013-05-30T17:44:57.767 に答える