String>>howManyMatch: Bug or feature ?
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 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
2015-03-24 13:53 GMT+01:00 Noury Bouraqadi <bouraqadi@gmail.com>:
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
Hi Nicolas,
On 24 Mar 2015, at 16:32, Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com> wrote: I think you're looking after the number of common chars only at beginning. Wouldn't the method finder hit a better match?
Yes. your right. I found the method I was actually needing that gives me the behavior I expected. String>>charactersExactlyMatching:
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?
What is misleading is that the howManyMatch: is in String. I believe it should be moved up to SequencableCollection Noury
participants (3)
-
Nicolas Cellier -
Noury Bouraqadi -
stepharo