1.3. Character Strings

Orc's character sequence representation is a string. Characters in Orc strings are drawn from the Unicode character set, and are encoded in the UTF-16 encoding form. (Note that Orc source code files are encoded in the UTF-8 encoding form.) Orc strings have an explicit length and are not zero-terminated. They are limited to a maximum length of 2^31-1 (2 147 483 647) characters.

1.3.1. Literals


[58]CharacterStringLiteral::= "Character+"""  

String literals are enclosed in quotation marks (U+0022). Any Unicode character can be placed between the quotation marks, except: line terminators (CR, LF, NEL [U+0085], LS [U+2028], FF, or PS [U+2029]) or a quotation mark. A reverse solidus (backslash) and its subsequent character are treated as follows:

  • \f: represents form feed (FF) (U+000C)

  • \n: represents line feed (LF) (U+000A)

  • \r: represents carriage return (CR) (U+000D)

  • \t: represents character tabulation (HT) (U+0009)

  • \u followed by 4 hexadecimal digits: represents the character at the Unicode code point indicated by the four hexadecimal digits

  • \u{ hexadecimal digits with space seperators }: represents the characters at the Unicode code points indicated by the hexadecimal digits, with multiple characters indicated by separating the hex digits by spaces (UTS 16 § 1.1 style)

  • \\: represents reverse solidus (backslash) (U+005C)

  • \": represents quotation mark (U+0022)

  • \ followed by any other character: represents that character

1.3.2. Operations

Notable string operations include:

  • All java.lang.String operations

  • Convert an Orc value to a string: write

  • Split a string into a list of strings corresponding to its lines: lines

  • Combine a list of strings into one multi-line string: unlines

  • Split a string into a list of strings corresponding to its words: words

  • Combine a list of strings into one multi-word strings: unwords

1.3.3. Type

A string value has type String.

1.3.4. Java calls

Orc strings are passed in calls to and returns from Java code as java.lang.String.

1.3.5. Examples

String Concatenation
{- Concatenate two strings -}

"hello" + " world"

"hello world"
String Functions
{- Showcase some Orc library string functions -}

Println("I go to the console") >>
unwords(["I", "like", "Orc"])

I go to the console
"I like Orc"

1.3.6. Related Links

Related Tutorial Sections