Melsi
Melsi

Reputation: 1462

Is there a function to cast string tokenizer to array

I am working over an hour to find a way to explode a string into a string array.

This method have failed for me:

lineFields = str.split("|");
System.out.print(lineFields.length); 

because it gives back an array of equal length to the string it self.

Then I read here that string tokenizer can explode a string, but unfortunately I cannot find a way to access the element randomly like lineFields[1].

I come from php and doing the simpliest things here looks so unusual, and of course I have searched the relative post on this forum, but still nothing close to my needs.

Upvotes: 2

Views: 964

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

  • Don't try to use StringTokenizer where split(...) should be used.
  • Just because your attempt to use split(...) isn't working doesn't mean that it's the wrong tool for the job.
  • You're using split wrong. Don't forget to escape your pipe, | String: "\\|"

Upvotes: 3

Related Questions