split() in String gives compilation error

N

Nishi Bhonsle

Hi:

I have a string that I want to split at the first occurence of "$"

Ex -->
String actStr = "/xx/ssdasdasd/asds/sdsdsd/sdsd$bjSt=d7b7cb90$sdsdsd=emtests2.<hostname>$type=sdasdsad$ctxType1=asdasdasd_sdasd";
String[] act2Str = new String[200];
String regex = "$";
for (int i = 0; i < act2.length; i++) {
act2 = actStr.split(regex,1);} //act2[] should contain "$bjSt=d7b7cb90$sdsdsd=emtests2.<hostname>$type=sdasdsad$ctxType1=asdasdasd_sdasd"

But I get an error at the split method when I try to compile this?

What could be the issue?

Thanks.
 
V

VisionSet

Nishi Bhonsle said:
Hi:

I have a string that I want to split at the first occurence of "$"

Ex -->
String actStr =
/xx/ssdasdasd/asds/sdsdsd/sdsd$bjSt=d7b7cb90$sdsdsd=emtests2. said:
String[] act2Str = new String[200];
String regex = "$";
for (int i = 0; i < act2.length; i++) {
act2 = actStr.split(regex,1);} //act2[] should contain

$bjSt=d7b7cb90$sdsdsd=emtests2. said:
But I get an error at the split method when I try to compile this?

What could be the issue?

split(String, int) returns a String array, you are trying to assign the
array returned to a String albeit an element of a String[]

you want something like:

String[] act2;

act2 = actStr.split(regex,1);

forget the for loop, you are trying to do to much
 
N

Nishi Bhonsle

VisionSet said:
Nishi Bhonsle said:
Hi:

I have a string that I want to split at the first occurence of "$"

Ex -->
String actStr =
/xx/ssdasdasd/asds/sdsdsd/sdsd$bjSt=d7b7cb90$sdsdsd=emtests2. said:
String[] act2Str = new String[200];
String regex = "$";
for (int i = 0; i < act2.length; i++) {
act2 = actStr.split(regex,1);} //act2[] should contain

$bjSt=d7b7cb90$sdsdsd=emtests2. said:
But I get an error at the split method when I try to compile this?

What could be the issue?

split(String, int) returns a String array, you are trying to assign the
array returned to a String albeit an element of a String[]

you want something like:

String[] act2;

act2 = actStr.split(regex,1);

forget the for loop, you are trying to do to much


I tried the above, but I get the following error --

C:\Test.java:24: cannot resolve symbol
symbol : method split (java.lang.String,int)
location: class java.lang.String
act2= actStr.split(regex,1);
^
1 error
 
V

VisionSet

you want something like:

String[] act2;

act2 = actStr.split(regex,1);

forget the for loop, you are trying to do to much

I tried the above, but I get the following error --

C:\Test.java:24: cannot resolve symbol
symbol : method split (java.lang.String,int)
location: class java.lang.String
act2= actStr.split(regex,1);
^
1 error

Well that has nothing to do with syntax, that is because the version of java
that is actually being used to compile does not support that method.
You are looking at Java 1.4+ docs and compiling under Java 1.3 or earlier.
 
N

Nishi Bhonsle

VisionSet said:
you want something like:

String[] act2;

act2 = actStr.split(regex,1);

forget the for loop, you are trying to do to much

I tried the above, but I get the following error --

C:\Test.java:24: cannot resolve symbol
symbol : method split (java.lang.String,int)
location: class java.lang.String
act2= actStr.split(regex,1);
^
1 error

Well that has nothing to do with syntax, that is because the version of java
that is actually being used to compile does not support that method.
You are looking at Java 1.4+ docs and compiling under Java 1.3 or earlier.

Thank you, that worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top