从c#中的String中提取字符串

时间:2017-08-20 06:27:44

标签: c# string hyperlink extract

我怎样才能得到这个:

Mu6AQUVX/YWxpYmFkOTE5KycrMzJAZ21haWwuY29t/?app_redirect=False"

从链接:

https://facebook.com/accounts/confirm_email/Mu6AQUVX/YWxpYmFkOTE5KycrMzJAZ21haWwuY29t/?app_redirect=False" 

提取此字符串:?

#039;ll see their posts in your feed.</p></td></tr><tr style=""><td height="30" style="line-height:30px;" colspan="1">&nbsp;</td></tr><tr><td style=""><a href="https://facebook.com/accounts/confirm_email/Mu6AQUVX/YWxpYmFkOTE5KycrMzJAZ21haWwuY29t/?app_redirect=False" style="color:#3b5998;text-decoration:none;display:block;width:370px;"><table border="0" width="100%" cellspacing="0" cellpadding="0" style="border-collapse:collapse;"><tr>

1 个答案:

答案 0 :(得分:0)

您可以使用以下函数在两个单词之间获取字符串:

public static String GetTextBetween(String source, String leftWord, String rightWord)
        {
            return
                Regex.Match(source, String.Format(@"{0}\s(?<words>[\w\s]+)\s{1}", leftWord, rightWord),
                            RegexOptions.IgnoreCase).Groups["words"].Value;
        }

使用您的参数调用以下函数:

GetTextBetween("your full text to search from", "start fix text", "end fix text")