Operations on strings.
Strings themselves have a set of methods associated with them. These methods can be invoked on any string literal or any variable bound to a string.
The methods documented here are only a subset of those available in the Java
implementation. In practice, strings in the Java implementation support all
methods provided by Java's
Return the length of the string.
-- Publishes: 4 "four".length()
string.substring(Integer, Integer) :: String
Return the substring of this string covered by the given half-open range.
-- Publishes: "orc" val s = "apple orchard" s.substring(6,9)
string.indexOf(String) :: Integer
Return the starting index of the first occurrence of the given string.
-- Publishes: 6 "apple orchard".indexOf("orc")
Print a value as a string to standard output.
For Java objects, this will call
toString() to convert
the object to a String.
Given a string representing an Orc value (using standard Orc literal syntax), return the corresponding value. If the argument does not conform to Orc literal syntax, halt with an error.
Read("true") -- publishes the boolean true | Read("1") -- publishes the integer 1 | Read("(3.0, )") -- publishes the tuple (3.0, ) | Read("\"hi\"") -- publishes the string "hi"
Given an Orc value, return its string representation using standard Orc literal syntax. If the value is of a type with no literal syntax, (for example, it is a site), return an arbitrary string representation which is intended to be human-readable.
Write(true) -- publishes "true" | Write(1) -- publishes "1" | Write((3.0, )) -- publishes "(3.0, )" | Write("hi") -- publishes "\"hi\""
Split a string into lines, which are substrings terminated by an endline or the end of the string. DOS, Mac, and Unix endline conventions are all accepted. Endline characters are not included in the result.
def lines(String) :: List[String] def lines(text) = arrayToList(text.split("\n|\r\n|\r"))
Append a linefeed, "\n", to each string in the sequence and concatenate the results.
def unlines(List[String]) :: String def unlines(line:lines) = line + "\n" + unlines(lines) def unlines() = ""
Split a string into words, which are sequences of non-whitespace characters separated by whitespace.
def words(String) :: List[String] def words(text) = arrayToList(text.trim().split("\\s+"))
Concatenate a sequence of strings with a single space between each string.
def unwords(List[String]) :: String def unwords() = "" def unwords([word]) = word def unwords(word:words) = word + " " + unwords(words)
Convert a string to a list of strings of length 1, where the list items are the characters of the given string.
Example: characters("Hello") = ["H", "e", "l", "l", "o"]
def characters(String) :: List[String] def characters(s) = def rest(Integer) :: List[String] def rest(i) = Ift (i >= s.length()) >>  | Ift (i <: s.length()) >> s.substring(i,i+1):rest(i+1) rest(0)