简体   繁体   中英

Extract string from a String in c#

How can I get this:

Mu6AQUVX/YWxpYmFkOTE5KycrMzJAZ21haWwuY29t/?app_redirect=False"

From the link:

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

Extracting this string:?

#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>

You can use below function to get string between two words:

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;
        }

Call below function with your arguments:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM