• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Parse String, and dynamically create URL

I have a problem where I am trying to send a site (UPS) series of tracking numbers, and unlike FEDEX which excepts a comma delimited string at the end of the URL string, UPS places URL variables with the numbers to be processed on there side.  So I need to make my string of

"111111111,22222222222,33333333333333,44444444444"

fit into a URL string so it reads

http://wwwapps.ups.com/etracking/tracking.cgi?tracknums_displayed=5&error_carried=yes&TypeOfInquiryNumber=T&HTMLVersion=4.0&sort_by=status&InquiryNumber1=111111111111&InquiryNumber2=2222222222222222&InquiryNumber3=3333333333333333&InquiryNumber4=44444444444&InquiryNumber5=&track=Track.

This means I must parse my string, and place each tracking # correctly into the new URL string.  I am new to Java syntax and am finding this all a bit daunting!

Anyone?
0
scotiaceilidh
Asked:
scotiaceilidh
  • 2
  • 2
1 Solution
 
cheekycjCommented:
so do you have a comma delimited list to begin with?

so you want something like this:
    String trackingIDList = "111111111111111,22222222222222222,3333333333333";
    java.util.StringTokenizer st = new java.util.StringTokenizer(trackingIDList, ",");
    int counter = 1;
    String URLString = "http://wwwapps.ups.com/etracking/tracking.cgi?tracknums_displayed=5&error_carried=yes&TypeOfInquiryNumber=T&HTMLVersion=4.0&sort_by=status&track=Track";
    while (st.hasMoreTokens()) {
      URLString += "&InquiryNumber" + counter + "=" + st.nextToken();
      counter++;
    }


trackingIDList is a comma-delimited list.
and URLString is the resulting URL.

If you have an array it makes it even easier:

    int[] trackingIDList = {111111111111111,22222222222222222,3333333333333};
    String URLString = "http://wwwapps.ups.com/etracking/tracking.cgi?tracknums_displayed=5&error_carried=yes&TypeOfInquiryNumber=T&HTMLVersion=4.0&sort_by=status&track=Track";
    for (int i=0; i<trackingIDList.length();i++) {
      URLString += "&InquiryNumber" + (i+1) + "=" + trackingIDList[i];
    }

HTH,
CJ
0
 
scotiaceilidhAuthor Commented:
Thanks cheekycj,
Let me Digest this and try it.
0
 
scotiaceilidhAuthor Commented:
Thank you,
I had not yet heard of that way of doing it.  I have learned.  thanks!
0
 
cheekycjCommented:
Glad I could help, Thanx for the "A".
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now