Help me!

Hi:

My code is:

String str="hello.jsp";

String[] temp=str.split(".",2);

System.out.println(temp[0]);

System.out.println(temp[1]);

When I run this code,the compiler told me a error in "

str.split(".",2)".

[323 byte] By [jack8048] at [2007-9-26 21:06:47]
# 1

jack,

Pl see below code that works. There is no method called split which you tried to use. Instead there is a class StringTokenizer which is very useful for splitting up Strings with a delimiter. Cheers.

import java.util.*;

public class TestStr

{

public static void main (String [] args)

{

String str = "hello.jsp";

StringTokenizer st = new StringTokenizer(str, ".");

int num = st.countTokens();

String [] arr = new String [num];

for (int i=0; i<num; i++)

{

arr [ i ] = st.nextToken();

System.out.println(arr [ i ]);

}

}

}

>

vrbhogaraju at 2007-7-3 20:25:35 > top of Java-index,Archived Forums,Java Programming...
# 2

even something easier

why not using substring class

say

you have

String blah =" Hello World";

then you could just say

System.out.println(blah.substring(0,5));

which would print

Hello

if you only wanne print World

you could say

System.out.println(blah.susbstring(5));

not the most smart way of doing it but it does the job and its easier to understand then Tokenizer =) for a begginer i mean

toolkitm at 2007-7-3 20:25:35 > top of Java-index,Archived Forums,Java Programming...
# 3
its substring NOT susbstring sorry about that
toolkitm at 2007-7-3 20:25:35 > top of Java-index,Archived Forums,Java Programming...