Blog

How to split the URL parameter name and values from a hyperlink

If you need to parse hyperlinks and retrieve parameter values, this post describes how to carry out this task.

When working with input data, there may be a requirement to parse hyperlinks and to extract the parameter names and values. Here's a demonstration of how to perform this task.

How to return a table of parameter names and values for a hyperlink

For this demonstration, let's assume that our hyperlink value is in a text input control called txtURL. The content of this text input control contains the following URL:

https://www.mywebsite.net/Search?customerFirstName=John&customerLastName=Doe&address1=88&city=New%20York&postalCode=412&country=GB

We can use the syntax below to return a table of the name-value pairs of parameters and arguments. This formula retrieves the content after the '?' by calling the Split function. It then calls the Split function with the '&' character to return a single-column table that contains the name/value parameter pairs. The formula then calls ForAll to iterate through this result and to Split the parameter name and values by the '=' character.

ForAll(Split(Last(Split(txtURL.Text,"?")).Value,
"&"),
With({param:Split(Value, "=")},
{Name:First(param).Value, Value:Last(param).Value}
)
)
Here's the result when we apply the formula to the Items property of a data table control. As this screenshot highlights, we can visualise the parameter names and values.



How to retrieve a hyperlink parameter value by name

To retrieve a specific parameter value, the easiest way is to extract the name-value pairs to a collection by following the formula.

ClearCollect(colParams,
ForAll(Split(Last(Split(txtURL.Text,"?")).Value,
"&"),
With({param:Split(Value, "=")},
{Name:First(param).Value, Value:Last(param).Value}
)
)
)

We can then return a specific parameter value by calling the LookUp function like so:

LookUp(colParams, Name="city").Value


Note that the input data may be URI encoded. Therefore, it may be further necessary to substitute the escape characters with the actual values. The formula below demonstrates how to substitute the "%20" character with a space.

Substitute(LookUp(colParams, Name="city").Value,
"%20",
" "
)

Conclusion

If you need to parse the hyperlinks and extract parameter names and values, this post demonstrates the formula to carry out this task.
  •   Categories: 
  • text