473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sorting variables from the URL

Stang02GT
1,208 Expert 1GB
Hello,

I posted something about this a couple weeks ago and was pointed into the right direction, but lack of time with school and other projects at work, i haven't been able to sit down and figure out how to accomplish this task and the code that i need to do it.

Here is my situation.

I have been asked to attempt to develop code that will alphabetize parameters after the input has been broken up by this code(which was given to me).....

Expand|Select|Wrap|Line Numbers
  1. int questionPos = inUrl.indexOf("?");
  2.              if (questionPos >= 0) {
  3.               StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
  4.  
  5.               StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
  6.  
  7.             while (tokenizer.hasMoreTokens()) {
  8.                String key = tokenizer.nextToken();
  9.         }
  10.  
  11.      }
In my searching and suggestions I have received, doing this could be done by

Arrays.sort()
or
Collections.sort()

My issue is I do not know where/how to begin developing code for this. I just looked at Java/Java script for the 1st time a couple weeks ago, so I am completely clueless.

Here is an example of the input

Expand|Select|Wrap|Line Numbers
  1. Ex. input: <a href="/ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=DESC">Federated Fund Name</a>

If someone could help me develop code for this so that i can begin to get my feet wet and have something to build off of i would greatly appreciate it.
Aug 27 '07 #1
9 1741
pbmods
5,821 Expert 4TB
Heya, Stang.

Changed thread title to better describe the problem (did you know that threads whose titles that do not follow the Posting Guidelines actually get FEWER responses?).
Aug 28 '07 #2
Logician
210 100+
I just looked at Java/Java script for the 1st time a couple weeks ago, so I am completely clueless.
Clue: Those are two different languages and this forum doesn't deal with the one you're being asked to use.
Aug 28 '07 #3
acoder
16,027 Expert Mod 8TB
Clue: Those are two different languages and this forum doesn't deal with the one you're being asked to use.
Moved to the Java forum where it belongs.
Aug 28 '07 #4
Nepomuk
3,112 Expert 2GB
I have been asked to attempt to develop code that will alphabetize parameters after the input has been broken up by this code(which was given to me).....

Expand|Select|Wrap|Line Numbers
  1. int questionPos = inUrl.indexOf("?");
  2.              if (questionPos >= 0) {
  3.               StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
  4.  
  5.               StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
  6.  
  7.             while (tokenizer.hasMoreTokens()) {
  8.                String key = tokenizer.nextToken();
  9.         }
  10.  
  11.      }
In my searching and suggestions I have received, doing this could be done by

Arrays.sort()
or
Collections.sort()

My issue is I do not know where/how to begin developing code for this. I just looked at Java/Java script for the 1st time a couple weeks ago, so I am completely clueless.

Here is an example of the input

Expand|Select|Wrap|Line Numbers
  1. Ex. input: <a href="/ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=DESC">Federated Fund Name</a>
OK, first of all you will need a main method.
Your basic class will look like this:
Expand|Select|Wrap|Line Numbers
  1. public class AlphabetizeParameters
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.  
  6.     }
  7. }
  8.  
Into that, you insert the code, which you were given:
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class AlphabetizeParameters
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         int questionPos = inUrl.indexOf("?");
  8.         if (questionPos >= 0)
  9.         {
  10.             StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
  11.             StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
  12.             sorted = new String[tokenizer.countTokens()/2+1];
  13.             while (tokenizer.hasMoreTokens())
  14.             {
  15.                 String key = tokenizer.nextToken();
  16.             }
  17.         }
  18.     }
  19. }
  20.  
I don't know, how the URL should be given to the function, but let's just assume, that it's given to the program as an arguemnt (so when you call it, it's something like "java AlphabetizeParameters /ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=D ESC"). Now you can access that as args[0].

You will need an Array (or whatever Container you want to use) to put the parameters into, so create one:
Expand|Select|Wrap|Line Numbers
  1. String[] parameters;
  2. ...
  3. parameters = new String[amountOfParameters];
  4.  
Then you have to put the parameters into the Array ([i]parameters = whateverStringItShouldBe;).
As soon as you've done that, you can sort your Array with Arrays.sort(parameters);

One last hint: You can't display an array of Strings with System.out.println(parameters);, however you can do this:
Expand|Select|Wrap|Line Numbers
  1. for(int i=0;i<parameters.length();i++)
  2.     System.out.println(parameters[i]);
  3.  
Aug 28 '07 #5
Stang02GT
1,208 Expert 1GB
OK, first of all you will need a main method.
Your basic class will look like this:
Expand|Select|Wrap|Line Numbers
  1. public class AlphabetizeParameters
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.  
  6.     }
  7. }
  8.  
Into that, you insert the code, which you were given:
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class AlphabetizeParameters
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         int questionPos = inUrl.indexOf("?");
  8.         if (questionPos >= 0)
  9.         {
  10.             StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
  11.             StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
  12.             sorted = new String[tokenizer.countTokens()/2+1];
  13.             while (tokenizer.hasMoreTokens())
  14.             {
  15.                 String key = tokenizer.nextToken();
  16.             }
  17.         }
  18.     }
  19. }
  20.  
I don't know, how the URL should be given to the function, but let's just assume, that it's given to the program as an arguemnt (so when you call it, it's something like "java AlphabetizeParameters /ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=D ESC"). Now you can access that as args[0].

You will need an Array (or whatever Container you want to use) to put the parameters into, so create one:
Expand|Select|Wrap|Line Numbers
  1. String[] parameters;
  2. ...
  3. parameters = new String[amountOfParameters];
  4.  
Then you have to put the parameters into the Array ([i]parameters = whateverStringItShouldBe;).
As soon as you've done that, you can sort your Array with Arrays.sort(parameters);

One last hint: You can't display an array of Strings with System.out.println(parameters);, however you can do this:
Expand|Select|Wrap|Line Numbers
  1. for(int i=0;i<parameters.length();i++)
  2.     System.out.println(parameters[i]);
  3.  

Thank you very much!
Aug 28 '07 #6
Stang02GT
1,208 Expert 1GB
You will need an Array (or whatever Container you want to use) to put the parameters into, so create one:
Expand|Select|Wrap|Line Numbers
  1. String[] parameters;
  2. ...
  3. parameters = new String[amountOfParameters];
  4.  
Then you have to put the parameters into the Array ([i]parameters = whateverStringItShouldBe;).
As soon as you've done that, you can sort your Array with Arrays.sort(parameters);

One last hint: You can't display an array of Strings with System.out.println(parameters);, however you can do this:
Expand|Select|Wrap|Line Numbers
  1. for(int i=0;i<parameters.length();i++)
  2.     System.out.println(parameters[i]);
  3.  

nepomuk,

First thank you very much for helping me. I apologize for my ignorance and lack of knowledge with Java. In the section above I would like to use an Array/ArrayList to do the sorting. This is now where i am getting confused, I follow what you are saying, but do to my lack of knowledge in this area.

Expand|Select|Wrap|Line Numbers
  1. String[] parameters;
  2. ...
  3. parameters = new String[amountOfParameters];
  4.  
I'm not sure what the above code should be doing, and what i need to add into the (...) part?
Aug 29 '07 #7
r035198x
13,262 8TB
You can display an array of Strings (or any other objects) using
Expand|Select|Wrap|Line Numbers
  1. Arrays.toString(array);
See the details in the docs for the Arrays class.
Aug 29 '07 #8
Nepomuk
3,112 Expert 2GB
nepomuk,

First thank you very much for helping me. I apologize for my ignorance and lack of knowledge with Java. In the section above I would like to use an Array/ArrayList to do the sorting. This is now where i am getting confused, I follow what you are saying, but do to my lack of knowledge in this area.

Expand|Select|Wrap|Line Numbers
  1. String[] parameters;
  2. ...
  3. parameters = new String[amountOfParameters];
  4.  
I'm not sure what the above code should be doing, and what i need to add into the (...) part?
The first line (String[] parameters;) defines an Array of Strings. At this point, the Array is not existent yet.

The last line (parameters = new String[amountOfParameters];) actually creates the Array. The Strings however still must be defined.

Inbetween both lines you have to find out, how many Elements (Strings) the Array will have.

After that, you'll have to give the Elements of the Array values.
You can display an array of Strings (or any other objects) using
Expand|Select|Wrap|Line Numbers
  1. Arrays.toString(array);
See the details in the docs for the Arrays class.
That is very usefull, thank you!
Aug 29 '07 #9
Stang02GT
1,208 Expert 1GB
Thanks again for all of your help!
Aug 29 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Topher | last post by:
Hi, I have a slight problem in that I want to list all the entries in a DBM file. I'm fine with sorting my the key, but I want to sort by one of the variables in the value - I know how to do...
9
by: p0wer | last post by:
Let's suppose I have this sample document: <root> <entry id="1" <date>2003-08-03</date> <param_1>5</param_1> <param_2>10</param_2> </entry> <entry id="2"> ...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
6
by: Dimitris Mandalidis | last post by:
Hello all, Suppose we have the following struct : struct foo { int a; int b; char *c; } And :
1
by: Guoqi Zheng | last post by:
Sir, The default paging of datagrid is somehow use too much resource, so I am using Stored procedure for the paging. You can find my Stored procedure at the end of this message. It works...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
5
KevinADC
by: KevinADC | last post by:
Introduction This discussion of the sort function is targeted at beginners to perl coding. More experienced perl coders will find nothing new or useful. Sorting lists or arrays is a very common...
1
by: mmorrison93 | last post by:
I've created my own custom gridview that derives from the System.Web.UI.WebControls.GridView class and am trying to implement my own sorting and paging mechanisms. The GridView class has two...
3
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.