Now, it didn't look that good in my message, but in the souce code it's formatted so that all equals are on the same tab level. This makes it really readable, and a lot better than adding strings together.
/Mathias
Interpolated Strings
-
- Posts: 50
- Joined: Fri Feb 16, 2018 7:52 am
Interpolated Strings
and one more thing...
This is the method for formatting values for sql expressions. When I format the date you can see that it's also possible to select which date format to use. I suppose this is possible in XSharp as well.
public static class DataReaderExtensions
{
public static string SqlValueString(this SqlDataReader reader, string colName)
{
object value = reader[colName];
Type type = value.GetType();
if (type == typeof(DBNull))
return "NULL";
if (ArrayHelper.InList(type,typeof(string),typeof(bool)))
return $"'{value}'";
if (type == typeof(DateTime))
return $"'{value:s}'";
return $"{value}";
}
}
/Mathias
This is the method for formatting values for sql expressions. When I format the date you can see that it's also possible to select which date format to use. I suppose this is possible in XSharp as well.
public static class DataReaderExtensions
{
public static string SqlValueString(this SqlDataReader reader, string colName)
{
object value = reader[colName];
Type type = value.GetType();
if (type == typeof(DBNull))
return "NULL";
if (ArrayHelper.InList(type,typeof(string),typeof(bool)))
return $"'{value}'";
if (type == typeof(DateTime))
return $"'{value:s}'";
return $"{value}";
}
}
/Mathias
Interpolated Strings
Don't get me wrong, but what exactly has this to do with interpolated strings?
K.
K.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
-
- Posts: 50
- Joined: Fri Feb 16, 2018 7:52 am
Interpolated Strings
It's examples of interpolated strings.
/Mathias
/Mathias
FFF wrote:Don't get me wrong, but what exactly has this to do with interpolated strings?
K.
Interpolated Strings
Hi Karl,
I was also confused at first, but $ is the symbol c# uses to specify interpolated strings, Matthias's sample code is full of them
Chris
I was also confused at first, but $ is the symbol c# uses to specify interpolated strings, Matthias's sample code is full of them
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Interpolated Strings
Hi Karl,
since I have been returned from my trip to the US (South Carolina and Georgia), I have changed the topic in the wiki:
https://docs.xsharp.it/doku.php?id=strings
Please let me know if I should add or change something else.
Wolfgang
since I have been returned from my trip to the US (South Carolina and Georgia), I have changed the topic in the wiki:
https://docs.xsharp.it/doku.php?id=strings
Please let me know if I should add or change something else.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Interpolated Strings
Hi Wolfgang,
hope you had a good trip.
Had a look, seems fine. Maybe in:
cString := ei"this is a "string". that references {cLocalVar}"
i'd use:
cString := ei"this is a "string", which resolves {xWhateverExpression}"
Lazy folks (like me ) might skip the new line you added behind. Also the "LocalVar" term implies, that there's a harder restriction of what may be used.
Karl
hope you had a good trip.
Had a look, seems fine. Maybe in:
cString := ei"this is a "string". that references {cLocalVar}"
i'd use:
cString := ei"this is a "string", which resolves {xWhateverExpression}"
Lazy folks (like me ) might skip the new line you added behind. Also the "LocalVar" term implies, that there's a harder restriction of what may be used.
Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Interpolated Strings
Hi Karl,
I have changed the article again, hopefully it is easier to understand now. Interpolated and extended strings are a really useful thing.
Wolfgang
P.S. yes, my holiday was great (and too short as all of them). We have hiked a lot and seen many animals (including alligators) in their habitats.
I have changed the article again, hopefully it is easier to understand now. Interpolated and extended strings are a really useful thing.
Wolfgang
P.S. yes, my holiday was great (and too short as all of them). We have hiked a lot and seen many animals (including alligators) in their habitats.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
-
- Posts: 50
- Joined: Fri Feb 16, 2018 7:52 am
Interpolated Strings
Hi,
sorry for not explaining more...
Yes, In C# you use $ for interpolated strings and @ for verbatim strings. The two things I wanted to show were;
1. SQL-statement (or text file row creation) strings can get a lot more readable with interpolated strings and verbatim strings in combination. If you compare with using StringBuilder or string concatination with +, there is a really big difference. As you can see I have all field names as constants which is really usefull if you want to find all occurrences of a field.
2. You can also specify the format. In my case I specified the date format in the SqlValueString method. You can also format numbers in a similar way.
/Mathias
sorry for not explaining more...
Yes, In C# you use $ for interpolated strings and @ for verbatim strings. The two things I wanted to show were;
1. SQL-statement (or text file row creation) strings can get a lot more readable with interpolated strings and verbatim strings in combination. If you compare with using StringBuilder or string concatination with +, there is a really big difference. As you can see I have all field names as constants which is really usefull if you want to find all occurrences of a field.
2. You can also specify the format. In my case I specified the date format in the SqlValueString method. You can also format numbers in a similar way.
/Mathias
-
- Posts: 50
- Joined: Fri Feb 16, 2018 7:52 am
Interpolated Strings
Found one more example of date formating that I have used. This one may be a little more useful....
In this case a filename is constructed by combining a language resource string with a formatted date.
string fileName = $"{AutoUpdatePricelistsFormLabels.LostPriceLinks} {DateTime.Now:yyyyMMdd HHmmss}.xlsx";
/Mathias
In this case a filename is constructed by combining a language resource string with a formatted date.
string fileName = $"{AutoUpdatePricelistsFormLabels.LostPriceLinks} {DateTime.Now:yyyyMMdd HHmmss}.xlsx";
/Mathias