c# - Get the last path of URL -


I am using the following code which is working well for most services, but sometime in the URL I got the user; V = 2; Mp and I just need to get the user , how should I manage it? I need some general solutions because I think that in some other URL, I can get different space charter

If the URL

  https: // ldmrrt Ct / odata / GBSRM / user; V = 2; MP string savannum = _uri.Segments.LastOrDefault ();  

If the URL is working well ...

Instead of:

  string savannum = _uri.Segments.LastOrDefault (); With  

:

  string savannum = _uri.Segments.LastOrDefault (). Split (new [] {';'}). first ();  

If you need some more flexible, where you can specify characters to include or skip, you can do something like this (little mess, you probably have some of it The parts should be removed as separate variables, etc.):

  // Note the _ and - characters in this example: URI _uri = new URI ("https: // ldmrrt .ct / odata / GBSRM / User_ex1-ex2; v = 2mp "); // It will return a string: "User_ex1-ex2" string service name = new string (_uri.Segments .LastOrDefault (.) Tackage (C => four.IsLatarOrgit (C) || (new letter [] {'_ ',' - '}) are included (c) .oere ());  

update, what I understand according to the question given below :):

You can just use that string. Replace () for this, or you use filtering to do something like this:

  // will return: "Userexex2v = 2mp" string savannah = new string (_uri.Segments. LostOrDefault). Where (c = & gt;! Ignore indexing (c) // punctuation. And any "_" or "-": and amp;! (New characters [] {'_', '-'}). ToArray ());  

If you use it in the production, remember you, clean it a little bit, e.g. Split from multiple variables, and define your four [] - array before use


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -