-1

I'm looking to grab a unique job ID from the middle of a url for a list of URL's. Here's the first URL.

https://cnhs.taleo.net/careersection/1/jobdetail.ftl?job=210001RQ&tz=GMT-07%3A00&tzname= 

I originally wrote:

int startIdx = args.Content.IndexOf("?job=") + 5;
int endIdx = args.Content.IndexOf("RQ", startIdx);
return args.Content.Substring(startIdx, endIdx - startIdx);

However, the proceeding URL's don't follow the format with 'RQ' following the job key. How do I grab that 6 digit job key from within a list of URL's with differing formatting after the job key? For example from the above URL, I want to grab 210001.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
CSpring
  • 1
  • 1
  • Does this answer your question? [Get URL parameters from a string in .NET](https://stackoverflow.com/questions/659887/get-url-parameters-from-a-string-in-net) – Yong Shun Jun 18 '21 at 02:43

2 Answers2

0

Please try the below code...hope this resolves your issue.

 Uri myUri = new Uri("https://cnhs.taleo.net/careersection/1/jobdetail.ftl?job=210001RQ&tz=GMT-07%3A00&tzname=");
 string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("job");
 string jobid = param1.Substring(0, 6);
Amit Verma
  • 2,450
  • 2
  • 8
  • 21
0
var uri = new Uri("https://cnhs.taleo.net/careersection/1/jobdetail.ftl?job=210001RQ&tz=GMT-07%3A00&tzname=");
  
var job = HttpUtility.ParseQueryString(uri.Query).Get("job");
  
var jobId = job.Substring(0, job.IndexOf("RQ"));
Chetan
  • 6,711
  • 3
  • 22
  • 32