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


fit into a URL string so it reads

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!

Who is Participating?
cheekycjConnect With a Mentor Commented:
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 = "";
    while (st.hasMoreTokens()) {
      URLString += "&InquiryNumber" + counter + "=" + st.nextToken();

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 = "";
    for (int i=0; i<trackingIDList.length();i++) {
      URLString += "&InquiryNumber" + (i+1) + "=" + trackingIDList[i];

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.