Back: Stream-testing Up: Base classes Forward: String class-instance creation   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.156 String

Defined in namespace Smalltalk
Superclass: CharacterArray
Category: Collections-Text
My instances represent 8-bit character strings. Being a very common case, they are particularly optimized.

Note that, if you care about multilingualization, you should treat String only as an encoded representation of a UnicodeString. The I18N package adds more Unicode-friendliness to the system so that encoding and decoding is performed automatically in more cases. In that case, String represents a case when the encoding is either unknown, irrelevant, or assumed to be the system default.

1.156.1 String class: instance creation  (class)
1.156.2 String class: multibyte encodings  (class)
1.156.3 String: accessing  (instance)
1.156.4 String: basic  (instance)
1.156.5 String: built ins  (instance)
1.156.6 String: converting  (instance)
1.156.7 String: filesystem  (instance)
1.156.8 String: printing  (instance)
1.156.9 String: regex  (instance)
1.156.10 String: testing functionality  (instance)


1.156.1 String class: instance creation

fromCData: aCObject
Answer a String containing the bytes starting at the location pointed to by aCObject, up to the first NUL character.

fromCData: aCObject size: anInteger
Answer a String containing anInteger bytes starting at the location pointed to by aCObject


1.156.2 String class: multibyte encodings

isUnicode
Answer false; the receiver stores bytes (i.e. an encoded form), not characters.


1.156.3 String: accessing

byteAt: index
Answer the ascii value of index-th character variable of the receiver

byteAt: index put: value
Store (Character value: value) in the index-th indexed instance variable of the receiver


1.156.4 String: basic

, aString
Answer a new instance of an ArrayedCollection containing all the elements in the receiver, followed by all the elements in aSequenceableCollection

= aCollection
Answer whether the receiver's items match those in aCollection


1.156.5 String: built ins

asCData: aCType
Convert the receiver to a CObject with the given type

at: anIndex
Answer the index-th indexed instance variable of the receiver

at: anIndex put: value
Store value in the index-th indexed instance variable of the receiver

basicAt: anIndex
Answer the index-th indexed instance variable of the receiver. This method must not be overridden, override at: instead

basicAt: anIndex put: value
Store value in the index-th indexed instance variable of the receiver This method must not be overridden, override at:put: instead

hash
Answer an hash value for the receiver

replaceFrom: start to: stop with: aString startingAt: replaceStart
Replace the characters from start to stop with new characters whose ASCII codes are contained in aString, starting at the replaceStart location of aString

replaceFrom: start to: stop withByteArray: byteArray startingAt: replaceStart
Replace the characters from start to stop with new characters whose ASCII codes are contained in byteArray, starting at the replaceStart location of byteArray

similarityTo: aString
Answer a number that denotes the similarity between aString and the receiver. 0 indicates equality, negative numbers indicate some difference. Implemented as a primitive for speed.

size
Answer the size of the receiver


1.156.6 String: converting

asByteArray
Return the receiver, converted to a ByteArray of ASCII values

asString
But I already am a String! Really!

asSymbol
Returns the symbol corresponding to the receiver

encoding
Answer the encoding of the receiver. This is not implemented unless you load the Iconv package.


1.156.7 String: filesystem

/ aName
Answer a File object as appropriate for a file named 'aName' in the directory represented by the receiver.

asFile
Answer a File object for the file whose name is in the receiver.


1.156.8 String: printing

displayOn: aStream
Print a representation of the receiver on aStream. Unlike #printOn:, this method strips extra quotes.

displayString
Answer a String representing the receiver. For most objects this is simply its #printString, but for CharacterArrays and characters, superfluous dollars or extra pair of quotes are stripped.

isLiteralObject
Answer whether the receiver is expressible as a Smalltalk literal.

printOn: aStream
Print a representation of the receiver on aStream

storeLiteralOn: aStream
Store a Smalltalk literal compiling to the receiver on aStream

storeOn: aStream
Store Smalltalk code compiling to the receiver on aStream


1.156.9 String: regex

=~ pattern
Answer a RegexResults object for matching the receiver against the Regex or String object pattern.

allOccurrencesOfRegex: pattern
Find all the matches of pattern within the receiver and collect them into an OrderedCollection.

allOccurrencesOfRegex: pattern do: aBlock
Find all the matches of pattern within the receiver and pass the RegexResults objects to aBlock.

allOccurrencesOfRegex: pattern from: from to: to
Find all the matches of pattern within the receiver and within the given range of indices. Collect them into an OrderedCollection, which is then returned.

allOccurrencesOfRegex: pattern from: from to: to do: aBlock
Find all the matches of pattern within the receiver and within the given range of indices. For each match, pass the RegexResults object to aBlock.

asRegex
Answer the receiver, converted to a Regex object.

copyFrom: from to: to replacingAllRegex: pattern with: aStringOrBlock
Returns the substring of the receiver between from and to. Any match of pattern in that part of the string is replaced using aStringOrBlock as follows: if it is a block, a RegexResults object is passed, while if it is a string, %n sequences are replaced with the captured subexpressions of the match (as in #%).

copyFrom: from to: to replacingRegex: pattern with: aStringOrBlock
Returns the substring of the receiver between from and to. If pattern has a match in that part of the string, the match is replaced using aStringOrBlock as follows: if it is a block, a RegexResults object is passed, while if it is a string, %n sequences are replaced with the captured subexpressions of the match (as in #%).

copyReplacingAllRegex: pattern with: aStringOrBlock
Returns the receiver after replacing all the matches of pattern (if any) using aStringOrBlock as follows: if it is a block, a RegexResults object is passed, while if it is a string, %n sequences are replaced with the captured subexpressions of the match (as in #%).

copyReplacingRegex: pattern with: aStringOrBlock
Returns the receiver after replacing the first match of pattern (if any) using aStringOrBlock as follows: if it is a block, a RegexResults object is passed, while if it is a string, %n sequences are replaced with the captured subexpressions of the match (as in #%).

indexOfRegex: regexString
If an occurrence of the regex is present in the receiver, return the Interval corresponding to the leftmost-longest match. Otherwise return nil.

indexOfRegex: regexString from: from to: to
If an occurrence of the regex is present in the receiver, return the Interval corresponding to the leftmost-longest match occurring within the given range of indices. Otherwise return nil.

indexOfRegex: regexString from: from to: to ifAbsent: excBlock
If an occurrence of the regex is present in the receiver, return the Interval corresponding to the leftmost-longest match occurring within the given indices. Otherwise, evaluate excBlock and return the result.

indexOfRegex: regexString ifAbsent: excBlock
If an occurrence of the regex is present in the receiver, return the Interval corresponding to the leftmost-longest match. Otherwise, evaluate excBlock and return the result.

indexOfRegex: regexString startingAt: index
If an occurrence of the regex is present in the receiver, return the Interval corresponding to the leftmost-longest match starting after the given index. Otherwise return nil.

indexOfRegex: regexString startingAt: index ifAbsent: excBlock
If an occurrence of the regex is present in the receiver, return the Interval corresponding to the leftmost-longest match starting after the given index. Otherwise, evaluate excBlock and return the result.

matchRegex: pattern
Answer whether the receiver is an exact match for the pattern. This means that the pattern is implicitly anchored at the beginning and the end.

matchRegex: pattern from: from to: to
Answer whether the given range of indices is an exact match for the pattern. This means that there is a match starting at from and ending at to (which is not necessarily the longest match starting at from).

occurrencesOfRegex: pattern
Returns count of how many times pattern repeats in the receiver.

occurrencesOfRegex: pattern from: from to: to
Return a count of how many times pattern repeats in the receiver within the given range of index.

occurrencesOfRegex: pattern startingAt: index
Returns count of how many times pattern repeats in the receiver, starting the search at the given index.

onOccurrencesOfRegex: pattern do: body
Find all the matches of pattern within the receiver and, for each match, pass the RegexResults object to aBlock.

onOccurrencesOfRegex: pattern from: from to: to do: aBlock
Find all the matches of pattern within the receiver and within the given range of indices. For each match, pass the RegexResults object to aBlock.

replacingAllRegex: pattern with: aStringOrBlock
Returns the receiver if the pattern has no match in it. Otherwise, any match of pattern in that part of the string is replaced using aStringOrBlock as follows: if it is a block, a RegexResults object is passed, while if it is a string, %n sequences are replaced with the captured subexpressions of the match (as in #%).

replacingRegex: pattern with: aStringOrBlock
Returns the receiver if the pattern has no match in it. If it has a match, it is replaced using aStringOrBlock as follows: if it is a block, a RegexResults object is passed, while if it is a string, %n sequences are replaced with the captured subexpressions of the match (as in #%).

searchRegex: pattern
A synonym for #=~. Answer a RegexResults object for matching the receiver against the Regex or String object pattern.

searchRegex: pattern from: from to: to
Answer a RegexResults object for matching the receiver against the Regex or String object pattern, restricting the match to the specified range of indices.

searchRegex: pattern startingAt: anIndex
Answer a RegexResults object for matching the receiver against the Regex or String object pattern, starting the match at index anIndex.

tokenize: pattern
Split the receiver at every occurrence of pattern. All parts that do not match pattern are separated and stored into an Array of Strings that is returned.

tokenize: pattern from: from to: to
Split the receiver at every occurrence of pattern (considering only the indices between from and to). All parts that do not match pattern are separated and stored into an Array of Strings that is returned.

~ pattern
Answer whether the receiver matched against the Regex or String object pattern.


1.156.10 String: testing functionality

isString
Answer `true'.



Back: String-regex Up: String Forward: Symbol   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on July, 23 2009 using texi2html