String.split

Hi AllI am stuck up while using String.split method in Webshere,pls any body of u can give altrenative logic for string.split,i need to use string object as delimeter (not a single char)
[200 byte] By [sachindwd] at [2007-9-30 21:19:05]
# 1
Hi thereWhy is the split method giving you trouble? Websphere shouldn't be affecting a Core Java API in any shape or form....Karianna
karianna at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 2
websphere not supporting 1.4 jdk,i am getting method not found error.pls answer my core question
sachindwd at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 3
> websphere not supporting 1.4 jdk,i am getting method> not found error.> pls answer my core questionYou need to phrase your question more clearly.Karianna
karianna at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 4

You are correct that the String class's split method was not introduced until JDK 1.4 and the current version of WebSphere does not support that version. However as an alternative you could try using the StringTokenizer class to tokenize a particular string. You will need to provide sample code of what you're trying to split in order for us to provide an example using the StringTokenizer class.

paternostro at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 5

I have got problem with the split method.

I have got the foloowing code:

String url = "http://localhost:8080/mywebsite/mypage.jsp?param1=value1&param2=value2";

String urlParts[] = url.split("[?]");

for(int i=0; i < urlParts.length; i++)

{

out.println("

url part " + i + ": " + urlParts);

}

The output gives some special character:

url part 0: http://localhost:8080/mywebsite/mypage.jsp

url part 1: param1=value1齧2=value2

why that special character is coming up instead of "&" symbol? How to get rid of that. OR Is there any other way to use split() method with regular expression?

forumans at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 6

Your original question does not reflect your current question. You were trying to use the split method which is only supported in JDK 1.4.x. However you mentioned using the method in the WebSphere container which caues a not found exception. I answered that as an alternative you could use the StringTokenizer class in lieu of the split method. For example:

import java.util.*;

public class Tokenize

{

public static void main(String args[])

{

String url = "http://localhost:8080/mywebsite/mypage.jsp?param1=value1&m2=value2";

StringTokenizer st = new StringTokenizer(url,"?");

while (st.hasMoreTokens())

{

System.out.println(st.nextToken());

}

}

}

paternostro at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 7
StringTokenizer is an alternative. But I am looking for correct Regular Expression to split the string at "?" location.
forumans at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 8

hi

String s3 = "~xaaaa~xbbbbb~xccccc~xddddd"; is string

i want to split it by taking ~x as delimeter ,and i dont want to use any jdk 1.4 methods like split,replace.only using stringtokenizer and substring methods i want to use ,and for this i want a logic or sample code,hope now it is clear

sachindwd at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 9
Hi,I think StringTokenizer would solve ur problemjava.util.StringTokenizer is the class works like Sting.splitthankusivajik
sivaji_sun at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 10
The StringTokenizer example I provided is fairly clear. Just make the appropriate parameter change to the constructor passing in the ~x string as the delimeter string.
paternostro at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 11

> The StringTokenizer example I provided is

> fairly clear. Just make the appropriate parameter

> change to the constructor passing in the ~x

> string as the delimeter string.

StringTokenizer will produce the correct result for the String that the OP posted. However, keep in mind that this will not produce the desired result if the String is like "aaaa~xbb~b~xccxc~xdddd" produces 6 tokenized Strings since StringTokenizer will tokenize on either ~ or x.

atmguy at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 12
Thats why i am asking for a altrenative method of split
sachindwd at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 13
If you need true regular expression support you have no choice to either resort to using a third party regular expression library or roll your own because the StringTokenizer class does not contain regular expression capability.
paternostro at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 14

Hi Guys...

I am not sure what version of JRE you are running your WSAD with..... because "split" is not supported in ealrier versions of JDK 1.4, and if my guess is correct you are using 1.3.1 or old version of JRE to compile your code in WSAD. Go to "Windows-Preferences-Java-Installed JREs" and check.

To use the split method, go to "Windows-Preferences-Java-Installed JREs" in WSAD and add the path to 1.4 JRE. and you should see the magic your self.

Let me know if you run into problems. Enjoy.

-Raghu

raghuram_vudathu at 2007-7-7 2:51:36 > top of Java-index,Administration Tools,Sun Connection...
# 15
THANKS YOU VERY MUCH
thuanphama at 2007-7-20 0:27:03 > top of Java-index,Administration Tools,Sun Connection...