Forums > Java

Parse text as list/Atom

October 11, 2007 | 10:38 am

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


October 11, 2007 | 10:54 am

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


October 12, 2007 | 3:16 pm

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


October 12, 2007 | 3:26 pm

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


October 12, 2007 | 3:35 pm

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
>


Viewing 5 posts - 1 through 5 (of 5 total)