Useful API Functions: Unterschied zwischen den Versionen
Cg (Diskussion | Beiträge) (→Stream) |
Cg (Diskussion | Beiträge) (→String) |
||
Zeile 3: | Zeile 3: | ||
== [[String API Functions | String]] == |
== [[String API Functions | String]] == |
||
All of the following operators are functional operators; meaning that they do not modify |
|||
the argument(s). |
|||
==== Literals (i.e. Constant Strings) ==== |
|||
'...' |
|||
::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 ==== |
|||
''string1'' = ''string2'' => Boolean |
|||
::compares case sensitive<br> |
|||
''string1'' sameAs: ''string2'' => Boolean |
|||
::compares case insensitive |
|||
==== Case Conversion ==== |
|||
''aString'' asLowercase => String |
|||
<br>''aString'' asUppercase => String |
|||
<br>''aString'' asUppercaseFirst => String |
|||
::return a case converted string |
|||
==== Finding Characters or Substrings ==== |
|||
====== Finding Characters ====== |
|||
''aString'' indexOf: ''aCharacter'' => Integer |
|||
::returns the 1-based index, or 0 if not found.<br> 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 |
|||
====== Finding Strings ====== |
|||
''aString'' indexOfString: ''aSubString'' [ caseSensitive:''boolean'' ] => Integer |
|||
::returns the 1-based index, or 0 if not found. |
|||
''aString'' includesString: ''aSubString'' [ caseSensitive:''boolean'' ] => Boolean |
|||
::returns true if the substring is included |
|||
''aString'' startsWith: ''aSubString'' [ caseSensitive:''boolean'' ] => Boolean |
|||
::returns true if the substring is a prefix |
|||
''aString'' endsWith: ''aSubString'' [ caseSensitive:''boolean'' ] => Boolean |
|||
::returns true if the substring is a prefix |
|||
==== Concatenation, Splitting and Joining ==== |
|||
''string1'' , ''string2'' (comma operator) => String |
|||
::returns the concatenated string. (i.e. <CODE>'hello' , 'world'</CODE> gives 'helloworld'.) |
|||
''aString'' splitOn: ''aCharacter'' => CollectionOfStrings |
|||
::splits the string into a collection of strings |
|||
''aCollectionOfStrings'' join: ''separator'' => String |
|||
::joins the string, inserting separator. |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,String String] |
Reference: [http://live.exept.de/ClassDoc/classDocOf:,String String] |
Version vom 26. September 2020, 01:14 Uhr
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.
Inhaltsverzeichnis
String[Bearbeiten]
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).
Reference: Stream
Number[Bearbeiten]
Literals (i.e. Constant Numbers)[Bearbeiten]
1234
16rFFAA or 0xaffe
2r0101 or 0b101010
NrXXX
- integer constant; decimal, hex, binary or any base N; integers may be arbitrary long
0.5
1e5
-1.2e-3
- float constant; actually double precision; use "q" for extra precision
(4/3)
- a fraction (numerator / denominator)
(4+3i)
- complex number (real part / imaginary part)
Arithmetic Operators[Bearbeiten]
Notice: there are no precedence rules for binary operators ('+', '-', '*', etc.) in Smalltalk. All binary operators are evaluated left to right. Use parentheses to specify order.
number1 + number2 => Number
number1 - number2 => Number
number1 * number2 => Number
number1 / number2 => Number
- any combination of types is possible (integer, float, fraction, complex)
number1 // number2 => Number
- truncating division (truncates towards negative infinity; i.e. the next smaller number)
number1 \\ number2 => Number
- remainder from above division
number1 quo: number2 => Number
- truncating division (truncates towards zero; same as "//" for positive numbers)
number1 rem: number2 => Number
- remainder from quo: (same as "\\" for positive numbers)
Math & Trigonometric Functions[Bearbeiten]
aNumber ln => Number
aNumber log10 => Number
aNumber log2 => Number
- logarithm; by default, an error is reported for negative numbers;
to get a complex result, use "Complex trapImaginary:[ aNumber ln ]".
- logarithm; by default, an error is reported for negative numbers;
aNumber sqrt => Number
- square root; by default, an error is reported for negative numbers;
to get a complex result, use "Complex trapImaginary:[ aNumber sort ]".
- square root; by default, an error is reported for negative numbers;
aNumber cbrt => Number
- cubic root.
aNumber exp => Number
number1 raisedTo: number2 => Number
- exponentiation
aNumber sin => Number
aNumber cos => Number
aNumber tan => Number
aNumber arcSin => Number
aNumber arcCos => Number
aNumber arcTan => Number
aNumber arcTan2 => Number
aNumber sinh => Number
aNumber cosh => Number
aNumber tanh => Number
- trigonometric / hyperbolic functions
Bitwise Operators[Bearbeiten]
ínteger1 bitAnd: integer2 => Integer
ínteger1 bitOr: integer2 => Integer
ínteger1 bitXor: integer2 => Integer
ínteger1 bitShift: count => Integer
ínteger1 leftShift: count => Integer
ínteger1 rightShift: count => Integer
ínteger1 bitTest: integer2 => Boolean
- bitwise operations
Reference: Number and its subclasses Integer, Float, Fraction, Complex