FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   array to string
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: array to string  (Read 247 times)
Vair


array to string
« on: Nov 16th, 2004, 2:45am »

Is there a method for the quick conversion of an array to a string for writing to a file (and an equivalent method to get it back into an array)?
 
Perhaps something similar to the way that lingo does it:
 
myString = string(myList)
 
and
 
myList = value(myString)
 
or does this have to be done the long way around?
 
fry


WWW
Re: array to string
« Reply #1 on: Nov 16th, 2004, 2:49am »

"join" will do it:
http://processing.org/reference/join_.html
 
// this will join the myList array with spaces
String myString = join(myList, " ");
 
another example on the ref page.
 
Vair


Re: array to string
« Reply #2 on: Nov 16th, 2004, 3:33am »

Thanks fry, I don't know why I missed that on the reference page.
 
Unfortunately it's completely useless for what I want to do - I'll have a go at summarising that in case anyone has any bright ideas about how I might be able to simplify before I go about feeding the data through loops to make formatted strings.
 
I have a two dimensional array that holds data about notes for sonia:
 
float[][] c1 = {                 { E[5], .2, .5}, {FS[5], .2, .5},
      { G[5], .2,  1},   {FS[5], .2, .5}, { E[5], .2, .5}, {DS[5], .2,  1},   ... etc.
 
The first element in the second dimension refers to the frequency of notes, drawn from one of a series of arrays that look like this:
 
float[] CS= {34.6478, 69.2957, 138.5913, 277.1826, 554.3653, 1108.731, 2217.461, 4434.922};
 
I want to slap the first array down into a file that can be read and written to by machine but also editable by hand - so the note _names_ are important as the frequencies are somewhat difficult to conceptualise. I've made it this way because I can't mix strings and floats in the same array.
 
Would I be right in thinking that there is no shortcut for this?
 
Pages: 1 

« Previous topic | Next topic »