[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Best way to find if a string begins with a particul
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] Best way to find if a string begins with a particular string.. |
Date: |
Wed, 17 Oct 2012 18:25:27 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121009 Thunderbird/16.0 |
Il 17/10/2012 17:43, Rick Flower ha scritto:
> By the way.. I added a few methods that I found very helpful in my text
> processing I've been doing lately.. Perhaps someone else might find these
> of interest -- they're modeled after similar methods already present but
> these work for stings instead of single characters. Enjoy!
>
> Stream extend [
> skipToString: aString [
> <comment: 'Skip to the specified string in the file -- must match
> the entire line!!'>
> [self atEnd] whileFalse: [
> self nextLine = aString ifTrue: [^true]].
> ^false
> ]
>
> findSubstring: aString [
> <comment: 'Skip to the specified sub-string in the stream'>
> | string |
> [self atEnd] whileFalse: [
> string := self nextLine.
> (string includesSubstring: aString caseSensitive: false)
> ifTrue: [
> "match found.. back the stream up to the start of the line"
> self position: (self position - string size - 1).
> ^true
> ]
> ].
> ^false
> ]
Isn't this skipToAll:
?
>
> upToString: aString [
> | nextLine ws |
> ws := WriteStream on: (self species new: 8).
> [self atEnd or: [(nextLine := self nextLine) = aString]]
> whileFalse: [ws nextPutAll: nextLine. ws nextPut: Character
> nl].
> ^ws contents
> ]
This is a bit like upToAll: but not quite, what about calling it
upToLine: instead?
> upUntilStringPrefixMissing: aString [
> | nextLine ws |
> ws := WriteStream on: (self species new: 8).
> [self atEnd or: [(nextLine := self nextLine) startsWith: aString]]
> whileTrue: [ws nextPutAll: nextLine. ws nextPut: Character nl].
> ^ws contents
> ]
upToLineStartingWith:
Paolo
> ]
>
>
> _______________________________________________
> help-smalltalk mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>
Re: [Help-smalltalk] Best way to find if a string begins with a particular string.., Gwenaƫl Casaccio, 2012/10/17