determine if a String contains a String

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

determine if a String contains a String

Mark Volkmann
What's the recommended way to determine if a String contains another  
String?
I found one way.

'*substring*' matches: string

I'm sure I could use a regular expression, but that seems like overkill.
At first I thought I should use include: or contains: from Collection,  
but apparently not.

---
Mark Volkmann




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

Re: determine if a String contains a String

NorbertHartl
On Sun, 2008-09-28 at 09:12 -0500, Mark Volkmann wrote:

> What's the recommended way to determine if a String contains another  
> String?
> I found one way.
>
> '*substring*' matches: string
>
> I'm sure I could use a regular expression, but that seems like overkill.
> At first I thought I should use include: or contains: from Collection,  
> but apparently not.
>
> ---
string includesSubstring: 'substring'

Norbert

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

Re: determine if a String contains a String

Rob Rothwell
While we are on the subject, is there an easy way to replace a substring with another one?  I couldn't figure out any other way than to collect: the substrings and then put them back together...

Rob

On Sun, Sep 28, 2008 at 10:27 AM, Norbert Hartl <[hidden email]> wrote:
On Sun, 2008-09-28 at 09:12 -0500, Mark Volkmann wrote:
> What's the recommended way to determine if a String contains another
> String?
> I found one way.
>
> '*substring*' matches: string
>
> I'm sure I could use a regular expression, but that seems like overkill.
> At first I thought I should use include: or contains: from Collection,
> but apparently not.
>
> ---
string includesSubstring: 'substring'

Norbert

_______________________________________________
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: determine if a String contains a String

Mark Volkmann
In reply to this post by NorbertHartl
On Sep 28, 2008, at 9:27 AM, Norbert Hartl wrote:

> On Sun, 2008-09-28 at 09:12 -0500, Mark Volkmann wrote:
>> What's the recommended way to determine if a String contains another
>> String?
>> I found one way.
>>
>> '*substring*' matches: string
>>
>> I'm sure I could use a regular expression, but that seems like  
>> overkill.
>> At first I thought I should use include: or contains: from  
>> Collection,
>> but apparently not.
>>
>> ---
> string includesSubstring: 'substring'


Thanks! It looks like the method name is "includesSubString:". Notice  
the last capital "S". That seems weird. There is another method named  
"includesSubstring:caseSensitive:" where that "s" isn't uppercase.

---
Mark Volkmann




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

Re: determine if a String contains a String

Janko Mivšek
In reply to this post by Rob Rothwell


Rob Rothwell wrote:
> While we are on the subject, is there an easy way to replace a substring
> with another one?  I couldn't figure out any other way than to collect:
> the substrings and then put them back together...


  aString copyReplaceAll: 'substring' with: 'another'


Janko


>
> Rob
>
> On Sun, Sep 28, 2008 at 10:27 AM, Norbert Hartl <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     On Sun, 2008-09-28 at 09:12 -0500, Mark Volkmann wrote:
>      > What's the recommended way to determine if a String contains another
>      > String?
>      > I found one way.
>      >
>      > '*substring*' matches: string
>      >
>      > I'm sure I could use a regular expression, but that seems like
>     overkill.
>      > At first I thought I should use include: or contains: from
>     Collection,
>      > but apparently not.
>      >
>      > ---
>     string includesSubstring: 'substring'
>
>     Norbert
>
>     _______________________________________________
>     Beginners mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: determine if a String contains a String

Rob Rothwell
Thanks...you're just all over the place today, aren't you?

Rob

On Sun, Sep 28, 2008 at 10:54 AM, Janko Mivšek <[hidden email]> wrote:


Rob Rothwell wrote:
While we are on the subject, is there an easy way to replace a substring with another one?  I couldn't figure out any other way than to collect: the substrings and then put them back together...


 aString copyReplaceAll: 'substring' with: 'another'


Janko



Rob


On Sun, Sep 28, 2008 at 10:27 AM, Norbert Hartl <[hidden email] <mailto:[hidden email]>> wrote:

   On Sun, 2008-09-28 at 09:12 -0500, Mark Volkmann wrote:
    > What's the recommended way to determine if a String contains another
    > String?
    > I found one way.
    >
    > '*substring*' matches: string
    >
    > I'm sure I could use a regular expression, but that seems like
   overkill.
    > At first I thought I should use include: or contains: from
   Collection,
    > but apparently not.
    >
    > ---
   string includesSubstring: 'substring'

   Norbert

   _______________________________________________
   Beginners mailing list
   [hidden email]
   <mailto:[hidden email]> ------------------------------------------------------------------------


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

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si

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


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