• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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: 240
  • 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.
 
Bartender
Posts: 4532
50
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
Bartender
Posts: 4532
50
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!