Show/Hide Toolbars

XSharp

There are a couple of different string types inside X#. For normal strings, the notation can be different for different dialects:

 

Literal

VO, FoxPro & Harbour

Vulcan & Core

'<char>'

String literal

Char literal*

'<char>...<char>'

String literal

Not Supported

"<char>...<char>"

String literal

String literal

e"<char>...<char>"

Extended string literal*

Extended string literal*

i"<char>.. <char>{expression}"

Interpolated string literal

Interpolated string literal

ei"<char>.. <char>{expression}" or

ie"<char>.. <char>{expression}"

Extended interpolated string literal*

Extended interpolated string literal*

 

The <char> literals in the table that are marked with an asterisk (*) may contain a special escape code:

 

Character

Description

Character that does NOT start with a backslash

Normal character

\\

Backslash

\"

Double quote

\'

Single quote

\0

0 character

\a

Alert

\b

Backspace

\f

Form feed

\n

Line feed

\r

New Line

\t

Tab

\v

Vertical tab

\x HEXDIGIT(1-4)

Hex number of character. 1-4 hex digits.

\u HEXGDIGIT (4 or 8)

Unicode number of character. 4 or 8 hex digits.

 

Interpolated strings inside X# can contain expressions in  the form of

{<interpolationExpression>[,<alignment>][::<formatString>]}

In C# the formatString is prefixed with a single colon. Please note that because in X# the colon (:) operator is the default member access operator for instance fields, properties and methods, it is not always possible to use that operator to separate expressions and format string. We have therefore changed that operator to the double colon (::). I  you compile with /allowdot+ then you can also use the single colon for the format separator.

To represent a literal '{' or '}' character you will have to duplicate them inside the string. The expressions inside the string are in italics in this example.

 

An example of this could be

FUNCTION Start() AS VOID
  local X := 2 as INT
  local Y := 3 as INT
  var pointMessage := i"The point {{{X}, {Y}}} is {Math.Sqrt(X * X + Y * Y)::F3} from the origin"
  Console.WriteLine(pointMessage)
 // Output is:
 // The point {2, 3} is 3.606 from the origin