Need to extract hostId from url

Hi,
I have one URL which is “/flexnet/operationsportal/fne/devices/viewDevice?publisherName=test&hostIdType=STRING&hostId=XXXXYYY-XX111-YY333-YYY333-WWW444-KKK999-sriram.kirsh123bc%40test.com&authPartyId=867433&authContactId=”
from this I need to extract only hostId.
Any suggestion how will I do this ?

i need to extract hostId value which is “XXXXYYY-XX111-YY333-YYY333-WWW444-KKK999-sriram.kirsh123bc%40test.com

Any suggestion would help

@davemitra
If we can rely on its existence it can be done with string functions:
strText.Split("&“c).Where(Function (x) x.StartsWith(“hostId=”)).First().Split(”="c)(1)

Another option could be Regex
or
myUri = new Uri(“http://dummy.com” + strText)
hostid = HttpUtility.ParseQueryString(myUri.Query).Get(“hostId”)
Retrieve_UriGetParameter.xaml (6.1 KB)

1 Like

thanks it worked, can you please explain a bit more on this function.
I didnt understand this one though I am getting the value.

Thanks in advance

sure:

first let me introduce another approach doing it more direct with api
strText = your url string starting with /
myUri = new Uri(“http://dummy.com” + strText)
hostid = HttpUtility.ParseQueryString(myUri.Query).Get(“hostId”)

Retrieve_UriGetParameter.xaml (6.1 KB)

About the statement:

  • strText.Split("&“c) -Split by & into a string Array
  • Where(Function (x) x.StartsWith(“hostId=”)) - filter the splits on items starting with hostId=
  • .First() - take first found item
  • .Split(”="c) - split filtered first item on =
  • (1) - take second element
1 Like

Hi,
thanks for the suggestion, i tried to use HttpUtility before but it was throwing error that " HttpUtility is not a member function of web"

do following for this
import system.web
close xaml open xaml in editor (e.g. notepad++)
add
<AssemblyReference>System.Web</AssemblyReference>

ensure that is present or add:
<x:String>System.Web</x:String>

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.