?
Solved

Parse String, and dynamically create URL

Posted on 2002-04-01
4
Medium Priority
?
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 480 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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