Useful API Functions

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen

This document lists most useful (and most often needed) classes and functions. Be aware, that there are many more to be found in either the class references or via the builtin class browser.

String[Bearbeiten]

All of the following operators are functional operators; meaning that they do not modify the argument(s).

Literals (i.e. Constant Strings)[Bearbeiten]

'...'

Smalltalk style string (as is; no escapes for special characters). Be aware, that this is inconvenient, if newlines, tabs or other non-graphical characters are to be in the string.

c'...'

C style string (supports the usual C-escapes, such as "\n" for newline, "\t" for tab or "\xHH" for hex codes)

e'...{expr}...'

C style with embedded expressions. These are evaluated and sliced into the string.

Comparing[Bearbeiten]

string1 = string2 => Boolean

compares case sensitive

string1 sameAs: string2 => Boolean

compares case insensitive

Case Conversion[Bearbeiten]

aString asLowercase
aString asUppercase
aString asUppercaseFirst

return a case converted string

Finding Characters or Substrings[Bearbeiten]

aString indexOf: aCharacter => Integer

returns the 1-based index, or 0 if not found.
  Notice that character constants are denoted as $x in Smalltalk (or "Character return", "Character newline", "Character tab"...)

aString lastIndexOf: aCharacter => Integer

searching from the end, returns the 1-based index, or 0 if not found.

aString includes: aCharacter => Boolean

returns true if the character is included, false if not

Concatenation, Splitting and Joining[Bearbeiten]

string1 , string2 (comma operator) => String

returns the concatenated string. (i.e. 'hello' , 'world' gives 'helloworld'.)

aString splitOn: aCharacter => CollectionOfStrings

splits the string into a collection of strings

aCollectionOfStrings join: separator => String

joins the string, inserting separator.

Reference: String inherits from: CharacterArray and SequenceableCollection and Collection

Collection[Bearbeiten]

Reference: Collection

Filename[Bearbeiten]

Reference: Filename

Stream[Bearbeiten]

Streams can be internal (eg. reading from a String) or external (eg. a file stream, pipe or socket).

Creating a Stream[Bearbeiten]

aString readStream

returns a stream to read from a string

aFilenameString asFilename readStream

returns a stream to read the file named aFilenameString

Testing[Bearbeiten]

aStream atEnd

returns true if no more elements are to be read

Reading Characters[Bearbeiten]

aStream next

returns the next character (as a character)

aStream next: 'count

returns the next count characters (as a string)

aStream nextByte

returns the next byte (as an integer)

aStream nextBytes: count

returns the next count bytes (as a byte array)

Reading Lines[Bearbeiten]

aStream nextLine

returns the next line (up to newLine) as a string

Positioning[Bearbeiten]

aStream position: pos

positions the stream; pos is 0-based (i.e. 0 is the very beginning)

aStream skip: count

positions the stream count elements further (i.e. reads over count elements)

Reference: Stream

Number[Bearbeiten]

Reference: Number and its subclasses Integer, Float, Fraction, Complex



Copyright © 2014-2024 eXept Software AG