Win a copy of Microservices in Action this week in the Web Services forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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: 245
  • 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: 5172
54
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: 5172
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!