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

TOPIC: Interpolated Strings

Interpolated Strings 9 months 3 weeks ago #5937

  wriedmann's Avatar wriedmann Offline Posts: 1567
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Interpolated Strings 9 months 3 weeks ago #5938

  MathiasHakansson's Avatar MathiasHakansson Offline Posts: 49
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 9 months 3 weeks ago #5939

  wriedmann's Avatar wriedmann Offline Posts: 1567
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Last edit: by wriedmann.

Interpolated Strings 1 month 4 weeks ago #8640

  SHirsch's Avatar SHirsch Offline Posts: 110
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 1 month 4 weeks ago #8641

  Chris's Avatar Chris Offline Posts: 1163
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 1 month 4 weeks ago #8648

  SHirsch's Avatar SHirsch Offline Posts: 110
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
Attachments:

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

  • Page:
  • 1
  • 2