A String is any sequence of characters enclosed by quotes. PTPScript does not support Unicode and so all characters are ASCII-based, meaning there are 256 different possibilities.

There is no practical limit to the size of Strings that PTPScript can support.

A String can be declared in various different ways:

  • Using single quotes ' '
  • Using double quotes " "
  • Using backticks ` `
  • Using triple single quotes ''' '''
  • Using triple double quotes """ """

Each type of String can contain all symbols except its own delimiters, and of course the PTPScript placeholder symbols - { and }. If a String should contain a delimiter, it will need to be escaped with the backslash character - \. If the backslash needs to appear before a delimiter, or at the end of the String, it should be doubled. Using triple quotes is useful when a String needs to contain various quote marks and you don't want to bother with escaping them. No "special" characters are recognised in any of the String formats, other than the escape character itself. If a String contains a placeholder, this placeholder will be evaluated before the String (see nested placeholders).

For example:

{ a = "hello" }
{ a = "123" }
{ a = "I'm still valid" }
{ b = 'Another string' }
{ b = 'John said, "hi!"' }
{ b = 'It\'s good to escape, once in a while' }
{ c = """Getting the hang of this? "Easy!" - 'Yup'""" }
{ d = '''Even triple-quotes can be escaped - look: \''' ...see?'''}

Converting to String

To explicitly convert a value to String, the String typecast operator - ~ - should be used. Some operators, such as the concatenation operator - ~ - also explictly convert a value to String. (Yes, they are the same symbol, but the former is a prefix operator, and the latter is an infix operator. See Operators for more information.)

When converting to String:

  • Boolean false is converted to a blank string - "", and true is converted to "1"
  • Numbers will be converted to a String representing their digits.
  • Arrays are currently converted to the string "Array". In the future this may well change.
ptpscript/types/string.txt · Last modified: 2007/01/24 10:15
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki