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.
I have got problem with the split method.
I have got the foloowing code:
String url = "http://localhost:8080/mywebsite/mypage.jsp?param1=value1¶m2=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?
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());
}
}
}
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
> 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.
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