Show/Hide Toolbars

XSharp

Interpolated strings is a feature that allows you to embed local variables, instance variables or other expressions inside literal strings.

X# supports two kinds of interpolated strings:

 

1.        Normal Interpolated strings: i"...."

 

This works like a normal X# string but with an embedded expression:

 

 FUNCTION Start AS VOID
    LOCAL Who AS STRING
     Who := "World"
     Console.Writeline( i"Hello {Who}")
     Console.Read()
    RETURN

2.        Extended Interpolated strings: ie"..." and ei"...."

This is a combination of an interpolated string and an extended string. In the example below the \t will be replaced with a tab character.

 

  FUNCTION Start AS VOID
    LOCAL Who AS STRING
     Who := "World"
     Console.Writeline( ie"Hello\t{Who}")
     Console.Read()
    RETURN

Notes

The expression parsing inside the interpolated strings recognizes:

SELF:

Local variables, Member variables and Properties with SELF: prefix and without this prefix

Other expressions must be in C# syntax for now, using the dot (.) operator as send operator.

 

The expression elements inside the string can use formatting notation just like the String.Format() notation. For example:

 

 FUNCTION Start AS VOID
    LOCAL i AS INT
     i := 42
     Console.Writeline( i"Hello {i:x}")   // i is printed in hex notation, so Hello 2a
     Console.Read()
    RETURN