Solved

Parse String, and dynamically create URL

Posted on 2002-04-01
4
195 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting NoSuchMethodError on accessing a spring mvc project 3 161
doubleChar java challenge 7 106
Java Script nested call 3 86
login jsp example 24 50
If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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