Parse text as list/Atom

Oct 11, 2007 at 10:38am

Parse text as list/Atom

Hi,

I want to input a filename as a list e.g.
34f_24353.aiff

and extract the part after the 34f_ as numbers

I’m thinking I would input via public void list(a)
then make a string (how do I do that?)
and then search for the underscore.

If anyone has an idea how to process this information
(the actual problem will be for say forty soundfiles) please post back. At the moment, I just get errors about the type – symbol

I was trying something like this:

public void list(Atom[] list)
{

Atom a;
Atom b;

a = list[0];
file_name = parse(a.toString());
//b = a.toString();
//file_name = parse(b);
}//end list process

#34128
Oct 11, 2007 at 10:54am

On 11 oct. 07, at 19:38, Andrew Robertson wrote:

> Hi,
>
> I want to input a filename as a list e.g.
> 34f_24353.aiff
>
> and extract the part after the 34f_ as numbers
>
> I’m thinking I would input via public void list(a)
> then make a string (how do I do that?)
> and then search for the underscore.
>
> If anyone has an idea how to process this information
> (the actual problem will be for say forty soundfiles) please post
> back. At the moment, I just get errors about the type – symbol
>
> I was trying something like this:
>
>
> public void list(Atom[] list)
> {
>
> Atom a;
> Atom b;
>
> a = list[0];
> file_name = parse(a.toString());
> //b = a.toString();
> //file_name = parse(b);
> }//end list process

You have to use the anything method to do that because 34f_24353.aiff
is not a list but a symbol:

public void anything(String s, Atom[] a)
{
String file_name = s;

// do whatever you want with that string
}

Cheers,
ej

#114705
Oct 12, 2007 at 3:16pm

Hi Emmanuel,

Thanks for your reply. That’s great. the filename is now a string.
if I wanted to convert that into an array of atoms (or strings) how would I do that?

Regards,
Andrew

#114706
Oct 12, 2007 at 3:26pm

On 13 oct. 07, at 00:16, Andrew Robertson wrote:

> Hi Emmanuel,
>
> Thanks for your reply. That’s great. the filename is now a string.
> if I wanted to convert that into an array of atoms (or strings) how
> would I do that?

If you want to have an array, you have to send more than one item.
For example if you send “34f_24353.aiff 34f_24354.aiff
34f_24355.aiff” (without the quotes) to your object, the anything
method will be called, the s string will contain 34f_24353.aiff, and
your Atom array will have a size of 2 (34f_24354.aiff and
34f_24355.aiff) that you can get with a[0].getString() and a
[1].getString() if I remember correctly.

Cheers,
ej

#114707
Oct 12, 2007 at 3:35pm

Hi Andrew,

String.split() (Java 1.5 +) or StringTokenizer (for older versions) may
be of help.


Owen

Andrew Robertson wrote:
> Hi Emmanuel,
>
> Thanks for your reply. That’s great. the filename is now a string.
> if I wanted to convert that into an array of atoms (or strings) how would I do that?
>
> Regards,
> Andrew
>

#114708

You must be logged in to reply to this topic.