• Post Reply Bookmark Topic Watch Topic
  • New Topic

Splitting strings in an array into another array  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program currently scans a .txt files content and stores it into an array. I now need to split the strings within the array with the delimiter ":" into another array. Currently I have:





Here:


is where my problem occurs, the program splits each string within the file_contents  array however it then overwrites the string thats located in the file_split array.


I tried this however I get this error:

Type mismatch: cannot convert from String[] to String

The txt file contains:




any advice would be appreciated.

Thanks,
Rob.
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not seeing where you define file_split to be a String array whose size is the file_length.
 
Saloon Keeper
Posts: 4116
48
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you're after but this will give you an array of arrays.

 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:I'm not sure what you're after but this will give you an array of arrays.

<nitpick>
You're better off using "+", because in this case you only want to include 1 or more spaces in the delimiter, not 0, and that can speed things up quite a bit (although "*" will also work).
Viz:</nitpick>

Lesson: Don't use '*' in regexes unless you specifically mean '0 or more'.

HIH

Winston
 
Carey Brown
Saloon Keeper
Posts: 4116
48
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I specifically mean "zero or more". Look at the data on line 10.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!