REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Datatypes: String!

Contents

Concept

Strings are a series of characters. All operations performable on series values can be performed on strings.

Format

String values are written as a sequence of characters surrounded by double quotes " " or braces {}. Strings enclosed in double quotes are restricted to a single line and must not contain unprintable characters.

"This is a short string of characters."

Strings enclosed in braces are used for larger sections of text that span multiple lines. All of the characters of the string, including spaces, tabs, quotes, and newlines are part of the string.

{This is a long string of text that will 
not easily fit on a single line of source.
These are often used for documentation
purposes.}

Braces are counted within the string, so a string can include other braces as long as the number of closing braces matches the number of opening braces.

{
This is another long string of text that would
never fit on a single line. This string also
includes braces { a few layers deep { and is 
valid because there are as many closing braces }
as there are open braces } in the string.
}

You can include special characters and operations in strings by prefixing them with a caret (^). Special characters include:

Character Definition
^" Inserts a double quote (").
^} Inserts a closing brace (}).
^^ Inserts a caret (^).
^/ Starts a new line.
^(line) Starts a new line.
^- Inserts a tab.
^(tab) Inserts a tab.
^(page) Starts a new page.
^(back) Erases one character to the left of the insertion point.
^(null) Inserts a null character.
^(escape) Inserts an escape character.
^(letter) Inserts control-letter (A-Z).
^(xx) Inserts an ASCII character by hexidecimal (xx) number. his format allows for expansion into unicode characters in the future.

Creation

Use make to create a pre-allocated amount of space for an empty string:

make string! 40'000 ; space for 40k characters

The to-string function converts data of other datatypes to a string! datatype:

probe to-string 29-2-2000
"29-Feb-2000"
probe to-string 123456.789
"123456.789"
probe to-string #888-555-2341
"888-555-2341"

Converting a block of data to a string with to-string has the effect of doing a rejoin, but without evaluating the block's contents:

probe to-string [123 456]
"123456"
probe to-string [225.225.225.0 none true 'word]
"225.225.225.0nonetrueword"

Related

Use string? or series? to determine whether a value is an string! datatype:

print string? "123"
true
print series? "123"
true

The functions form and mold are closely related to strings, as they create strings from other datatypes. The form function makes a human readable version of a specified datatype, while mold makes a REBOL readable version.

probe form "111 222 333"
"111 222 333"
probe mold "111 222 333"
{"111 222 333"}


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin