Reputation: 65097
How do I create a class method to get the argument from a string input?
string value GetArugmentValueByName (string input, string name)
Example
myInput="code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp6&
client_id=21302922996.apps.googleusercontent.com&
client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&
redirect_uri=https://www.example.com/back&
grant_type=authorization_code";
If I do this
string myGrantType = GetArugmentValueByName(myInput, "grant_type");
the value of myGrantType should equal "authorization_code"
Upvotes: 1
Views: 200
Reputation: 5350
You can use ParseQueryString to parse out the params into a name value collection, then index into that for the param you are looking for.
public string GetArgumentValueByName(string queryString, string paramName)
{
var paramCol = HttpUtility.ParseQueryString(queryString);
return paramCol[paramName] ?? string.Empty;
}
Upvotes: 5