Splitting strings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Splitting strings

Damien Pollet
Hi,

is there anything like ruby's String#split in Smalltalk? (split the
string at string occurences or regexp matches)

I found SequenceableCollection#piecesCutWhere: or String#findTokens
but I need to split at occurences of a substring. I must also admit my
problem is with VW... I did try in the method finder in Squeak, but
without much success.

--
 Damien Pollet
 type less, do more
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Splitting strings

Mathieu SUEN
Damien Pollet a écrit :

> Hi,
>
> is there anything like ruby's String#split in Smalltalk? (split the
> string at string occurences or regexp matches)
>
> I found SequenceableCollection#piecesCutWhere: or String#findTokens
> but I need to split at occurences of a substring. I must also admit my
> problem is with VW... I did try in the method finder in Squeak, but
> without much success.
>

You can use #subString:

'About somthing' subStrings: ' '  -> #('About' 'somthing')

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Splitting strings

Nicolas Cellier-3
In reply to this post by Damien Pollet
Oups, i sent my answer to squeak-dev... forward to beginners

I see at least two alternatives:
- Stream
- VBRegex

If you have a single separator string, then Stream already has the upToAll: method (leave stream positioned before occurence...)

| testString sep subStrings inputStream |
testString := 'split that string in this language'.
sep := 'th'.
subStrings := Array new writeStream.
inputStream := testString readStream.
[inputStream atEnd]
        whileFalse: [
                subStrings nextPut: (inputStream upToAll: sep).
                inputStream throughAll: sep].
^subStrings contents

VBRegex is more powerfull of course (it can match several different separators at once).
I let you inquire about it.

Nicolas


Damien Pollet:

> Hi,
>
> is there anything like ruby's String#split in Smalltalk? (split the
> string at string occurences or regexp matches)
>
> I found SequenceableCollection#piecesCutWhere: or String#findTokens
> but I need to split at occurences of a substring. I must also admit my
> problem is with VW... I did try in the method finder in Squeak, but
> without much success.
>
> --
>  Damien Pollet
>  type less, do more
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

________________________________________________________________________
iFRANCE, exprimez-vous !
http://web.ifrance.com

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Splitting strings

Damien Pollet
In reply to this post by Mathieu SUEN
On 7/26/06, mathieu <[hidden email]> wrote:
> You can use #subString:

Not really... my goal is to parse a bibtex author field, e.g. a list
of particle Name, FirstName SecondName items separated by "and"
keywords. I could use #findTokens to separate the words.

--
 Damien Pollet
 type less, do more
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Splitting strings

Nicolas Cellier-3
In reply to this post by Damien Pollet
I Forward because my mistake with squeak-dev...

Philippe Marschall:

> What's with #splitOn: , #subStrings:  and #findBetweenSubStrs: except
> that they don't support regex and have all more or less the same
> responsibility?
>
> Philippe
>
> 2006/7/26, ncellier @ ifrance. com <[hidden email]>:
> >
> > I see at least two alternatives:
> > - Stream
> > - VBRegex
> >
> > If you have a single separator string, then Stream already has the upToAll: method (leave stream positioned before occurence...)
> >
> > | testString sep subStrings inputStream |
> > testString := 'split that string in this language'.
> > sep := 'th'.
> > subStrings := Array new writeStream.
> > inputStream := testString readStream.
> > [inputStream atEnd]
> >         whileFalse: [
> >                 subStrings nextPut: (inputStream upToAll: sep).
> >                 inputStream throughAll: sep].
> > ^subStrings contents
> >
> > VBRegex is more powerfull of course (it can match several different separators at once).
> > I let you inquire about it.
> >
> > Nicolas
> >
> > Damien Pollet:
> > > Hi,
> > >
> > > is there anything like ruby's String#split in Smalltalk? (split the
> > > string at string occurences or regexp matches)
> > >
> > > I found SequenceableCollection#piecesCutWhere: or String#findTokens
> > > but I need to split at occurences of a substring. I must also admit my
> > > problem is with VW... I did try in the method finder in Squeak, but
> > > without much success.
> > >
> > > --
> > >  Damien Pollet
> > >  type less, do more
> > > _______________________________________________
> > > Beginners mailing list
> > > [hidden email]
> > > http://lists.squeakfoundation.org/mailman/listinfo/beginners
> > >
> >
> >
> > ________________________________________________________________________
> > iFRANCE, exprimez-vous !
> > http://web.ifrance.com
> >
> >
> >
> >
> >
> >
>

________________________________________________________________________
iFRANCE, exprimez-vous !
http://web.ifrance.com

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Splitting strings

Roel Wuyts
In reply to this post by Damien Pollet
If this is in VW as you mentioned in a previous post, I have a full  
Bibtex parser you can use (made with SmaCC, a parser generator). We  
use it to generate webpages, filtered bibfiles, and other things from  
bibtex (http://decomp.ulb.ac.be/roelwuyts/publications/ is generated  
with the tool, for example).

If you're interested I can tell you where to find it.


On 26 Jul 2006, at 09:24, Damien Pollet wrote:

> On 7/26/06, mathieu <[hidden email]> wrote:
>> You can use #subString:
>
> Not really... my goal is to parse a bibtex author field, e.g. a list
> of particle Name, FirstName SecondName items separated by "and"
> keywords. I could use #findTokens to separate the words.
>
> --
> Damien Pollet
> type less, do more
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Splitting strings

Damien Pollet
On 7/26/06, Roel Wuyts <[hidden email]> wrote:
> If this is in VW as you mentioned in a previous post, I have a full
> Bibtex parser you can use (made with SmaCC, a parser generator). We

Hehe, precisely (BibOuter ?)

Problem is I prefer to use the more robust Surname, Name scheme of
naming authors but it seems the parser doesn't handle this. Maybe I
should investigate extending the SmaCC parsers?

--
 Damien Pollet
 type less, do more
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Splitting strings

Roel Wuyts
Investigating the SmaCC parsers would be useful, yes, if you're not  
afraid to do it. I don't have time to look at it currently, so any  
help is appreciated :-)


On 26 Jul 2006, at 17:41, Damien Pollet wrote:

> On 7/26/06, Roel Wuyts <[hidden email]> wrote:
>> If this is in VW as you mentioned in a previous post, I have a full
>> Bibtex parser you can use (made with SmaCC, a parser generator). We
>
> Hehe, precisely (BibOuter ?)
>
> Problem is I prefer to use the more robust Surname, Name scheme of
> naming authors but it seems the parser doesn't handle this. Maybe I
> should investigate extending the SmaCC parsers?
>
> --
> Damien Pollet
> type less, do more
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Splitting strings

Mathieu SUEN
2006/7/26, Roel Wuyts <[hidden email]>:
> Investigating the SmaCC parsers would be useful, yes, if you're not
> afraid to do it. I don't have time to look at it currently, so any
> help is appreciated :-)

I think you have to write your own grammar (that is how it works with
SmaCC) for parsing BibTeX. Load de SmaCCDev package from squeaksource.

Math

>
>
> On 26 Jul 2006, at 17:41, Damien Pollet wrote:
>
> > On 7/26/06, Roel Wuyts <[hidden email]> wrote:
> >> If this is in VW as you mentioned in a previous post, I have a full
> >> Bibtex parser you can use (made with SmaCC, a parser generator). We
> >
> > Hehe, precisely (BibOuter ?)
> >
> > Problem is I prefer to use the more robust Surname, Name scheme of
> > naming authors but it seems the parser doesn't handle this. Maybe I
> > should investigate extending the SmaCC parsers?
> >
> > --
> > Damien Pollet
> > type less, do more
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Splitting strings

stéphane ducasse-2
In reply to this post by Damien Pollet

On 26 juil. 06, at 17:41, Damien Pollet wrote:

> On 7/26/06, Roel Wuyts <[hidden email]> wrote:
>> If this is in VW as you mentioned in a previous post, I have a full
>> Bibtex parser you can use (made with SmaCC, a parser generator). We
>
> Hehe, precisely (BibOuter ?)
>
> Problem is I prefer to use the more robust Surname, Name scheme of
> naming authors but it seems the parser doesn't handle this. Maybe I
> should investigate extending the SmaCC parsers?

please do :)

>
> --
> Damien Pollet
> type less, do more
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Splitting strings

Damien Pollet
On 7/27/06, stéphane ducasse <[hidden email]> wrote:
> please do :)

done :p

--
 Damien Pollet
 type less, do more

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners