Page 3 of 3
Interpolated Strings
Posted: Wed Aug 29, 2018 6:51 am
by wriedmann
Hi,
this is really great:
Code: Select all
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:
https://docs.xsharp.it/doku.php?id=strings
Interpolated Strings
Posted: Wed Aug 29, 2018 7:01 am
by MathiasHakansson
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.
https://docs.microsoft.com/en-us/dotnet ... at-strings
/Mathias
Interpolated Strings
Posted: Wed Aug 29, 2018 7:14 am
by wriedmann
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
Interpolated Strings
Posted: Mon Apr 22, 2019 6:50 pm
by SHirsch
Hi,
another question for this topic:
I would like to use an interpolated string on a dictionary.
Short example
Code: Select all
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
Interpolated Strings
Posted: Mon Apr 22, 2019 7:33 pm
by Chris
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.
Interpolated Strings
Posted: Tue Apr 23, 2019 5:36 am
by SHirsch
Hi Chris,
in C# it compiles without backslash.
Code: Select all
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.
- VS_IntelliSense_InterpolatedStrings.jpg (12.41 KiB) Viewed 1858 times
Stefan