PDA

View Full Version : String Parsing Help


BakerCo
12-05-2006, 10:20 PM
I am having a hard time finding a good way to parse a string and store it in an array... here is an example:

I parsed this from a file:
(320 -192 448) (0 -192 448) (0 -192 0)"

the original string of text in the file looked like this:
"id1" "(320 -192 448) (0 -192 448) (0 -192 0)"

I would like to have that string end up in an array like this:
#([320,-192,448],[0,-192,448],[0,-192,0])
any help would be greatly appreciated

Thanks
-Baker

ypuech
12-05-2006, 10:53 PM
Hi Jonathan,

I think that the best solution is to use filterString method in string class like this :

parsedLine = "(320 -192 448) (0 -192 448) (0 -192 0)"
filteredLine = filterString parsedLine "() "

pointArray = #()
for i = 1 to filteredLine.count by 3 do
(
point = Point3 (filteredLine[i] as float) (filteredLine[i+1] as float) (filteredLine[i+2] as float)
append pointArray point
)

print pointArray

BakerCo
12-05-2006, 11:10 PM
WOW thanks alot where did you find this?

Thanks again
-Baker

ypuech
12-05-2006, 11:29 PM
Hi Jonathan,

It's my own code. I've coded it for you :).

Moreover filterString is a very handy method when parsing strings.

BakerCo
12-06-2006, 12:36 AM
thank you very much I am very appreciative ... not much else to say except thanks alot I need the help :D

-Baker

CGTalk Moderation
12-06-2006, 12:36 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.