String represents an array of Chars.
Strings can be written literally using double quotes:
A sequence of string literals will be concatenated together:
Backslash is the escape character. See Literals: Characters.
Note that, while Char does not support encodings aside from ASCII—such as multi-byte encodings like UTF-8 and UTF-16, or the full Latin-1 (ISO 8859-1) character set—Chars with negative values are perfectly legal, and may be strung together in strings that use these encodings.
The SuperCollider IDE uses UTF-8 (a superset of ASCII) to decode and display strings, which means that the string
"🎹🙄🎻😂🎚️🎛️🎤😍" can be written in the editor, posted in the post window, and treated for the most part like any other string. However, because non-ASCII UTF-8 characters consist of two or more bytes, and a SuperCollider String's members are one-bit Chars, concepts of size and indexing may not behave intuitively. For instance, the "
size" of the string above is 38, not 8, and the value of its first index is
-16, which is not a valid ASCII value at all but rather the signed 8-bit representation of the first byte of the UTF-8 value of the piano keyboard emoji (🎹),
Read the entire contents of a File and return them as a new String.
Provided for backwards compatibility.
the value of
Platform.resourceDir, which is the base resource directory of SuperCollider.
Please use Platform: *resourceDir instead.
Strings respond to .at in a manner similar to other indexed collections. Each element is a Char.
Returns an Array of ASCII values of the Strings's characters.
Note that if a string contains multi-byte UTF-8 characters, this array will not be of the same length as the number of visible characters, nor will it necessarily be an array of valid 7-bit ASCII values.
Returns an integer less than, equal to or greater than zero, depending on whether the receiver should be sorted before the argument, is equal to the argument or should be sorted after the argument. This is a case sensitive compare.
Returns a Boolean whether the receiver should be sorted before the argument.
Returns a Boolean whether the receiver should be sorted after the argument.
Returns a Boolean whether the receiver should be sorted before the argument, including the same string.
Returns a Boolean whether the receiver should be sorted after the argument, including the same string.
Returns a Boolean whether the two Strings are equal.
Returns a Boolean whether the two Strings are not equal.
Prints the string to the current post window.
Prints the string and a carriage return to the current post window.
Prints a formatted string with arguments to the current post window. The % character in the format string is replaced by a string representation of an argument. To print a % character use \\% .
Prepends an error banner and posts the string.
Prepends a warning banner and posts the string.
Legacy method (although due to widespread use, it will not be removed). This is identical to
Compiles a String containing legal SuperCollider code and returns a Function.
Compile and execute a String containing legal SuperCollider code, returning the result.
Compile, execute and print the result of a String containing legal SuperCollider code.
Returns a String formatted for compiling.
Return a Symbol derived from the String.
Return an Integer derived from the String. Strings beginning with non-numeric characters return 0.
Return a Float derived from the String. Strings beginning with non-numeric characters return 0.
Return a concatenation of the two strings.
Return a concatenation of the two strings with a space between them.
path, as components of a filesystem path on the host operating system. The strings are joined to avoid duplicate path separators.
this ends with a path separator and
path begins with one, then the separator in
path is dropped. If there is a path separator on either side, this has the same effect as using
++. If neither side has a path separator, the platform's preferred separator ('\' on Windows, '/' otherwise) is added.
path concatenated. If
path was a PathName, the result is a PathName; otherwise, it is a String.
Concatenate this string with the following args.
Same as -catArgs, but with spaces in between.
Same as -catArgs, but with commas in between.
Note the inversion of the arguments:
stringToSearch.findRegexp(regexp)(and similar for
findRegexp follows the pattern established by String: -find, where the receiver is the string to be searched.
matchRegexp follows the pattern of matchItem, where the receiver is the pattern to match and the first argument is the object to be tested. This is a common source of confusion, but it is based on this precedent.
POSIX regular expression matching. Returns true if the receiver (a regular expression pattern) matches the string passed to it. The start is an offset where to start searching in the string (default: 0), end where to stop.
regexp.matchRegexp(stringToSearch)and not the other way around! See above: String: Regular expressions.
POSIX regular expression search.
Like -findAll, but use regular expressions. So unlike findRegexp, it will just return the indices of the
Match a regular expression at the given offset, returning the match and the length of the match in an Array, or nil if it doesn't match. The match must begin right at the offset.
Returns the index of the string in the receiver, or nil if not found. If ignoreCase is true, find makes no difference between uppercase and lowercase letters. The offset is the point in the string where the search begins. string may be a String or a Char.
Same like -find, but starts at the end of the string.
Returns the indices of the string in the receiver, or nil if not found.
Returns a Boolean indicating if the String contains string.
Same as -contains, but case insensitive.
Returns a Boolean indicating if the String contains string beginning at the specified index.
Same as -containsStringAt, but case insensitive.
Returns true if this string begins/ends with the specified other string.
The other string
Rotate the string by n steps.
Randomize the order of characters in the string.
Like -tr, but with Strings as well as Chars as arguments.
Returns a formatted string with arguments. The % character in the format string is replaced by a string representation of an argument. To print a % character use \\% .
Add the escape character (\) before any character of your choice.
Return this string enclosed in double-quote (
" ) characters.
Return this string enclosed in space characters.
Return this string followed by dashes in the next line (
Transliteration. Replace all instances of from with to.
Pad this string with string so it fills size character.
Number of characters to fill
Return this string with uppercase letters.
Return this string with lowercase letters.
Returns a new String with all RTF formatting removed.
Returns an Array of Strings split at the separator. The separator is a Char, and is not included in the output array.
Print the String on stream.
Where relevant, the current working directory is the same as the location of the SuperCollider app and the shell is the Bourne shell (sh). Note that the cwd, and indeed the shell itself, does not persist:
It is however possible to execute complex commands:
Also on os x applescript can be called via osascript:
Should you need an environment variable to persist you can use -setenv.
Execute a UNIX command asynchronously using the standard shell (sh).
A Function that is called when the process has exited. It is passed two arguments: the exit code and pid of the exited process.
A Boolean that controls whether or not the output of the process is displayed in the post window.
Similar to -unixCmd except that the stdout of the process is returned (synchronously) rather than sent to the post window.
Executes a UNIX command synchronously using the standard shell (sh).
Error code of the UNIX command
Execute the String in a new terminal window (asynchronously).
The shell used to execute the string.
Set the environment variable indicated in the string to equal the String value. This value will persist until it is changed or SC is quit. Note that if value is a path you may need to call -standardizePath on it.
Returns the value contained in the environment variable indicated by the String.
Set the environment variable to nil.
Make a directory from the given path location.
Returns an Array containing all paths matching this String. Wildcards apply, non-recursive.
Load and execute the file at the path represented by the receiver.
Post a warning if path doesn't point to any file.
If a function is passed, it is called with each path as argument.
Load and execute the file at the path represented by the receiver, interpreting the path as relative to the current document or text file. Requires that the file has been saved. This can be used e.g. to load initialization code from files in the same folder.
Warn if a file is not found.
A function that is called for each file path that is found.
Convert the receiver from a relative path to an absolute path, relative to the current document or text file. Requires that the current text file has been saved. Absolute paths are left untransformed.
Open file, directory or URL via the operating system. On macOS this is implemented via
open, on Linux via
xdg-open and on Windows via
Also see -+/+ for path concatenation.
The term "path separator" is a platform-independent term for the character(s) that can be used to separate components of a path. On Windows, both forward slash "/" and backward slash "\\" are path separators. On POSIX-based systems like macOS and Linux, only forward slash is allowed.
Return a new string suitable for use as a filename in a shell command, by enclosing it in single quotes (
' ). If the string contains any single quotes they will be escaped.
Return this path as an absolute path by prefixing it with File: *getcwd if necessary.
Return this path as relative to the specified path.
The path to make this path relative to.
Appends a path separator if one is not already present.
Removes a trailing path separator if one is present.
Return the filename from a Unix path.
Return the directory name from a Unix path.
Split off the extension from a filename or path and return both in an Array as [path or filename, extension].
Parse this string as YAML/JSON.
parseYAML but parse a file directly instead of a string. This is faster than reading a file into a string and then parse it.
Create a new Document with this.
Create a new Document from the path corresponding to this. The selection arguments will preselect the indicated range in the new window. Returns this.
Returns the path for the helpfile named this, if it exists, else returns nil.
Performs -findHelpFile on this, and opens the file it if it exists, otherwise opens the main helpfile.
Returns class StringInspector.
The following methods must be called within an Window-drawFunc or a SCUserView-drawFunc function, and will only be visible once the window or the view is refreshed. Each call to Window-refresh SCUserView-refresh will 'overwrite' all previous drawing by executing the currently defined function.
Pen.stringAtPoint, Pen.stringInRect, Pen.stringCenteredIn, Pen.stringLeftJustIn, Pen.stringRightJustIninstead.
Draws the String into the given Rect using the Font and Color specified.
Draws the String into the given Rect using the Font and Color specified.
Tries to return a Rect with the size needed to fit this string if drawn with given font.
Strips whitespace at the beginning and end of the string.
The stripped string
Like -unixCmdGetStdOut but returns the lines in an Array instead.
an Array of each line of output