User Tools

Site Tools


Literals, prefixes and suffixes

String literals

A string literal is delimited with the double quotation mark .

"This is a string"

Please note that in the VO dialect a string can also be delimited with the quotation mark ' .

'This is a string' // valid only in the VO dialect, not in Core or Vulcan

If you need to specify special characters or single quotation marks in a string, you need an escaped string, prefixed with e:

e"This is an escaped string with a new line \nand a double \" quotation mark"

There are also interpolated strings that can contain variables:

local cValue := "guys" as string
Console.WriteLine( i"Hi {cValue}" ) // Hi guys

Since in the VO dialect a string can also be defined with single quotation marks, there is no possibility for the compiler to see a difference between a single character string and a char. Therefore you should prefix a char literal with a c like this:

cChar := c'\r'

For more details please see Strings and their prefixes and String, Char and Byte

Numeric literals

As default, every number with decimals is treated as Double datatype, and every number without decimals as Int32 datatype. Values that are too large to fit in a Int32 are seen as Int64. If you need to specify what type a numeric literal should take, use suffixes:

  • d for Double
  • s for Single
  • m for Decimal
  • b for Binary

You can also use a prefix of 0x to specify a hexadecimal value. Sample code:

Console.WriteLine( "123.45  is a " + (123.45 ):GetType():Name )      // Double
Console.WriteLine( "123     is a " + ( 123 ):GetType():Name )              // Int32
Console.WriteLine( "10000000000 is a " + ( 10000000000 ):GetType():Name )  // Int64
Console.WriteLine( "123s    is a " + ( 123s ):GetType():Name )             // Single
Console.WriteLine( "123d    is a " + ( 123d ):GetType():Name )             // Double
Console.WriteLine( "123dm   is a " + ( 123m ):GetType():Name )             // Decimal
Console.WriteLine( "0x111   has a decimal value of " + 0x111:ToString() )  // decimal 273
Console.WriteLine( "0b111   has a decimal value of " + 0b111:ToString() )  // decimal 7

For explanations why these suffixes differ from these on C#, please see this X# forum post: Correct syntax for floats (look at the 3rd message from Chris Pyrgas)

literals.txt · Last modified: 2018/08/20 04:05 by wolfgangriedmann