there is a string
string s = "http://captcha.site.com/captcha?key=5d11165823bed8a529794a6253f7ec6fab099f8f748424efddb2506f4dfe"; how to get everything that comes after "key ="? "5d11165823bed8a529794a6253f7ec6fab099f8f748424efddb2506f4dfe"
there is a string
string s = "http://captcha.site.com/captcha?key=5d11165823bed8a529794a6253f7ec6fab099f8f748424efddb2506f4dfe"; how to get everything that comes after "key ="? "5d11165823bed8a529794a6253f7ec6fab099f8f748424efddb2506f4dfe"
And let's try to do it right and securely! All means there.
using System.Web; // ... var s = "http://captcha.site.com/captcha?key=5d11165823bed8a52979" + "4a6253f7ec6fab099f8f748424efddb2506f4dfe"; var uri = new Uri(s); var query = uri.Query; var parts = HttpUtility.ParseQueryString(query); var key = parts["key"]; You have to connect the assembly System.Web.
Why regulars if there is a ready-made parser?
= can be encoded ( https://www.google.com/search?q=%D0%BF%D1%8B%D1%89%D1%8C ), my code will automatically decode it. - VladDMicrosoft.AspNet.WebApi.Client , which is PCL - in it the specified method is implemented as an extension method of the Uri class. Perhaps someone will be useful in the development of platforms other than Windows, so as not to fence the bike. ) - Sergey Rufanov [?&]key=(\w+) Take the first group.
You can get regular expressions: https?:\/\/[^\s]+?key=([A-z0-9]*)
using System.Text.RegularExpressions; class Program { static void Main(string[] args) { const string InputStr = "http://captcha.site.com/captcha?key=5d11165823bed8a529794a6253f7ec6fab099f8f748424efddb2506f4dfe"; var match = Regex.Match(InputStr, "[\?&]key=(?<key>\\w+)"); var key = match.Groups["key"].Value; } } [\?&] - ReinRausSource: https://ru.stackoverflow.com/questions/432684/
All Articles