2015-03-24 13:53 GMT+01:00 Noury Bouraqadi <[email protected]>:

> Hi,
>
> The normal behavior
> 'abc' howManyMatch: 'abd' --> 2.
>
> I got suprized the way Blanks and new lines are handled.
>
> '\**' withCRs howManyMatch: '\\**' withCRs. --> 2 instead of 1
>
> 'ab\ **' withCRs howManyMatch: 'ab\\**' withCRs. --> 4 instead of 3
>
> '\ **' withCRs howManyMatch: '\\**' withCRs. --> 3 instead of 1
>
> 'ab\ **' withCRs howManyMatch: 'ab\\**' withCRs. --> 5 instead of 3
>
> The behavior is the same in both Pharo 3 and Pharo 4.
>
> Reading the code of does not help me understand why it's this way
>
> String>>howManyMatch: string
>         "Count the number of characters that match up in self and aString."
>         | count shorterLength |
>
>         count := 0.
>         shorterLength := self size min: string size.
>         1 to: shorterLength do: [:index |
>                 (self at: index) = (string at: index )
>                         ifTrue: [ count := count + 1 ]].
>         ^  count
>
>
> Noury
>

Noury,
I think you're looking after the number of common chars only at beginning.
Wouldn't the method finder hit a better match?

The method works as advertised in the comment. Though I find it very
questionnable:
Doesn't "match" imply some other semantic like pattern matching (and thus
things like wild character etc...)?
Is such specific behavior usefull? Really? Why/Where?


>
> Afin de contribuer au respect de l'environnement,
> merci de n'imprimer ce courriel qu'en cas de necessite
>
> Please consider the environment before you print
>
>
>
>

Reply via email to