Home > Back-end >  Parse a graph url string C#
Parse a graph url string C#

Time:10-15

I have the following string

https://graph.microsoft.com/v1.0/groups/group-id/members/user-id/$ref

How do I parse the url string and get the value user-id?

var a = requestStep; //requestStep is of type Microsoft.Graph.BatchRequestStep
var b = requestStep.Request.RequestUri;

b has the value:

https://graph.microsoft.com/v1.0/groups/group-id/members/user-id/$ref

enter image description here

CodePudding user response:

There are a few ways to skin that cat ...

string url = "https://graph.microsoft.com/v1.0/groups/group-id/members/user-id/$ref";
string userId = url.Split('/')[url.Split('/').Length - 1];
Console.WriteLine(userId);

CodePudding user response:

You can also use the following regex pattern :

^https:\/\/graph\.microsoft\.com\/. \/members\/(. )\/\$ref$

enter image description here

  • Related