Welcome, Guest
Username: Password: Remember me
Share your code snippets, screen shots etc. here
  • Page:
  • 1
  • 2

TOPIC:

Interpolated Strings 29 Aug 2018 08:51 #5937

  • wriedmann
  • wriedmann's Avatar


  • Posts: 3366
  • Hi,

    this is really great:
    local nValue as decimal
    nValue := 123.45m	
    Console.WriteLine( i"nValue: {nValue:######.0000}" ) // nValue: 123,4500
    Console.WriteLine( i"nValue {nValue:F6}" )  // nValue: 123,450000

    even if the .NET formatting strings are less powerful than the pictures we know from VO.

    Wolfgang

    P.S. I have also adjusted the wiki: docs.xsharp.it/doku.php?id=strings
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Interpolated Strings 29 Aug 2018 09:01 #5938

    • MathiasHakansson
    • MathiasHakansson's Avatar


  • Posts: 50
  • Yes, Wolfgang, it's really convenient.

    I find the .net formatting strings is less useful for numbers than VO's when it comes to common numbers and amounts. The formatting in .net however covers a wider field (like hex-values). I think the date formatting in .net is easier with all the standard formats that are ready to use.

    docs.microsoft.com/en-us/dotnet/standard...meric-format-strings

    /Mathias

    Please Log in or Create an account to join the conversation.

    Interpolated Strings 29 Aug 2018 09:14 #5939

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Mathias,

    yes, I find the options for numeric less useful than the picture strings in VO. And after all, input of numerics is very important in any business application.

    But I see not why the picture clauses in the X# runtime could not be extended by the development team when we need that.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Last edit: by wriedmann.

    Interpolated Strings 22 Apr 2019 20:50 #8640

    • SHirsch
    • SHirsch's Avatar


  • Posts: 279
  • Hi,
    another question for this topic:
    I would like to use an interpolated string on a dictionary.
    Short example
    VAR dict := Dictionary<STRING, OBJECT>{}
    dict:Add("PL_ID", "0001")
    VAR val := ei"pl_id: {dict[\"pl_id\"]}"

    This throws three errors:
    error XS8076: Missing close delimiter '}' for interpolated expression started with '{'.
    error XS1056: Unexpected character '\'
    error XS1003: Syntax error, ']' expected

    Is this a bug or wrong syntax?

    Regards
    Stefan

    Please Log in or Create an account to join the conversation.

    Interpolated Strings 22 Apr 2019 21:33 #8641

    • Chris
    • Chris's Avatar


  • Posts: 3981
  • Hi Stefan,

    Not sure if it should be considered a bug, but I think this is stretching interpolated strings a it too far! The point of using them is to make the code more readable, and this does not seem really readable to me :)

    I would instead use String.Format() for such complex embedding of values in strings:

    VAR val := System.String.Format("pl_id: {0}", dict["pl_id"])

    I realize this is not answering your question, but I thought it might be helpful to give this different suggestion.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Interpolated Strings 23 Apr 2019 07:36 #8648

    • SHirsch
    • SHirsch's Avatar


  • Posts: 279
  • Hi Chris,

    in C# it compiles without backslash.
    var dict = new Dictionary<String, Object>();
    dict.Add("PL_ID", "0001");
    var val = $"pl_id: {dict["PL_ID"]}";

    IntelliSense is a bit better than XIDE in this part. I think recognizing the brackets and change the color for the interpolated expression back to normal code color would help readability.



    Stefan

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    • 2