Solved

Parse String, and dynamically create URL

Posted on 2002-04-01
4
196 Views
Last Modified: 2010-04-01
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
Comment
Question by:scotiaceilidh
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 120 total points
ID: 6910758
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
 
LVL 1

Author Comment

by:scotiaceilidh
ID: 6910787
Thanks cheekycj,
Let me Digest this and try it.
0
 
LVL 1

Author Comment

by:scotiaceilidh
ID: 6910813
Thank you,
I had not yet heard of that way of doing it.  I have learned.  thanks!
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6912872
Glad I could help, Thanx for the "A".
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
immutable object concept 5 127
Reading data  from excel sheet and displaying 1 89
squirrelPlay java challenge 40 158
IE doesn't Invoke servlet in iframe 1 115
Are client relationship the only driver of a successful MSP? While important, client relationships are only one component. Learn how else MSPs can broaden their horizon and differentiate themselves.
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question