Solved

Parse String, and dynamically create URL

Posted on 2002-04-01
4
190 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
Comment Utility
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
Comment Utility
Thanks cheekycj,
Let me Digest this and try it.
0
 
LVL 1

Author Comment

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

Expert Comment

by:cheekycj
Comment Utility
Glad I could help, Thanx for the "A".
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Session migration 1 93
eclipse problems view not showing all the time 4 86
java beans and EJBs 5 182
Set up Wildfly 10 8 318
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now