We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Import list of float values from file
Page Index Toggle Pages: 1
Import list of float values from file? (Read 527 times)
Import list of float values from file?
Apr 30th, 2008, 5:05am
 
Does anyone have an idea how to import a list of Float values from a text file into a processing array?

Thank You!
Re: Import list of float values from file?
Reply #1 - Apr 30th, 2008, 9:11am
 
Take a look at the loadStrings method(http://processing.org/reference/loadStrings_.html). If your values come line by line you can use the example from loadStrings and convert every line into floats using float(). Otherwise all your values are in one line and separated by comma, space or something else, you have to split the line (http://processing.org/reference/split_.html) and then convert the result array items into floats.
Re: Import list of float values from file?
Reply #2 - May 1st, 2008, 12:59am
 
Thank you for your response.

The problem is when I implement the loadStrings() function, it feeds 9 lines of code, for three strings. Is there a way to import only the actual text?

Ex:

Heres an example of what the text file (*.rtf) looks like:

222
333
434

Here is what loadString() returns:

[0] "{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf270"
[1] "{\fonttbl\f0\fswiss\fcharset0 Helvetica;}"
[2] "{\colortbl;\red255\green255\blue255;}"
[3] "\margl1440\margr1440\vieww9000\viewh8400\viewkind0"
[4] "\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx79
20\tx8640\ql\qnatural\pardirnatural"
[5] ""
[6] "\f0\fs24 \cf0 222\"
[7] "333\"
[8] "434}"

The values are shot out in lines 6, 7, 8.

I would then use parseFloat() on the string array to turn it into an array of floats.

Any suggestions to use loadStrings() to import an array of only the actual text seen in the import file?
Re: Import list of float values from file?
Reply #3 - May 1st, 2008, 9:34am
 
You need to save your RTF file as a plain old txt file. RTF has lots of extra junk in it that's not necessary for a simple data file.
Page Index Toggle Pages: 1