I need some help parsing a string array returned from method.

current results:
Here is the test Information: SPRCBT - Algebra 1 - Form 9D - Joe Smith
Here is my Test Name [Ljava.lang.String;@5ec24193

Any ideas on the best way to return the values of the array instead if the index?

if (i == 2){
System.out.println("Here is the test Information: " + testPage.getTestInfo());
test = testPage.getTestInfo().split(" - ");
System.out.println("Here is my Test Name " + test);
}

Recommended Answers

All 6 Replies

best way to return the values of the array instead if the index?

Using The index is the ONLY way to get elements out of an array.

If you want a utility to print the contents of an array look at the toString method of the Arrays class.

Using The index is the ONLY way to get elements out of an array.

Or an enhanced for-each loop (may be easier)?

I have gotten a bit further with the following code. Now I need to assign Algebra 1 = testName and Form 9D = formName.

Any Ideas?

results:
Here is the test Information: SPRCBT - Algebra 1 - Form 9D - Gerald CORTEZ
SPRCBT
Algebra 1
Form 9D
Gerald CORTEZ

if (i == 2){
				
System.out.println("Here is the test Information: " + testPage.getTestInfo());
testInfo = testPage.getTestInfo();
String del = " - ";
String[] tokens = testInfo.split(del);
for (int j = 0; j < tokens.length; j++)
System.out.println(tokens[j]);
}

I need to assign Algebra 1 = testName and Form 9D = formName.

Your variable names can not contain spaces. This is how you should code it:
Algebra1 = testName;
Form9D = formName;

When assigning a value to a variable, put the variable name on the left of the assignment operator (=) and the value to be assigned on the right side of the operator.

Hi Norm. Sorry to appear contradictory, but aren't "Algebra 1" and "Form 9D" pieces of the data? In which case testName and formName would be the variable names. In which case it would me something like

testName = tokens[1]; // "Algebra 1" is the second token

I think the OP's statement about assigning was just "imprecise".
(If I'm wrong just say and I'll butt out)

Yes. The OP was being a bit imprecise and I was being too literal.
I was trying to get the OP to say in more detail what it was he wanted.
He was using the syntax of an assignment statement:
Algebra 1 = testName
vs
I need to assign the String "Algebra 1" to the variable: testName

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.