Interpolated Strings

Public forum to share code snippets, screen shorts, experiences, etc.
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Interpolated Strings

Post by FFF »

Guys, Wolfgang,
just found "the" thing about interpolated strings, and thought maybe i'm not the only one a bit slow ;)

VAR i:= 4 AS INT
VAR c AS STRING
c:= i"Bla {i} blabla"

i.e.: the syntax allows to insert ANY type into a string, handling silently the conversions! That's really cool.

Even something like
c:= i"Bla {oMainWindow} blabla"
works, inserting the classname.

So you might consider adding/adapting the docs, as up2now the samples insert only strings, which is relatively pointless ;)
Karl
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Interpolated Strings

Post by wriedmann »

Hi Karl,
Currently I am on holiday, will add better samples after my return.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Interpolated Strings

Post by FFF »

Ey, saw your "status" in whatsapp - cool location....
Enjoy your free days, i'm almost at the end of mine <sigh>

Karl
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am

Interpolated Strings

Post by Karl-Heinz »

Hi Karl,

I'm eagerly waiting for the next C# feature to become true.

local dw as dword

dw := 12_123_789

instead of the boring

dw := 12123789

;-)

regards
Karl-Heinz
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Interpolated Strings

Post by Chris »

I like that a lot, too!
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Interpolated Strings

Post by FFF »

Could it be that you didn't get the drift of my post?
All samples i saw for i"..." used strings as insertion, and that is really old, as i can do the same with simple +...+, so i never understood the usecase :)
But for any other type it comes handy...

K.
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am

Interpolated Strings

Post by Karl-Heinz »

? 12.22 + " " + today() + " " + setcentury() + " " + 12123789

Maybe even that will work someday ;-)

? 12.22 + " " + today() + " " + setcentury() + " " + 12_123_789
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Interpolated Strings

Post by FFF »

That all works (but only) for "?"...
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Interpolated Strings

Post by robert »

Mmm, that (underscore delimiters inside numeric literals) should not be too difficult to implement I think.
I'll see what I can do.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
MathiasHakansson
Posts: 50
Joined: Fri Feb 16, 2018 7:52 am

Interpolated Strings

Post by MathiasHakansson »

I use this a lot. I have an old C# application built around datasets and i use this when building sql strings.

plInfo.SqlUpdate =
$@"UPDATE {Const.TBL_PRICE_LIST_STRUCT}
SET
{Const.COL_COLUMN_NUM} = {dataReader.SqlValueString(Const.COL_COLUMN_NUM)}
,{Const.COL_START_POSITION} = {dataReader.SqlValueString(Const.COL_START_POSITION)}
,{Const.COL_END_POSITION} = {dataReader.SqlValueString(Const.COL_END_POSITION)}
,{Const.COL_IS_ACTIVE} = {dataReader.SqlValueString(Const.COL_IS_ACTIVE)}
,{Const.COL_IMPORT_FORMAT} = {dataReader.SqlValueString(Const.COL_IMPORT_FORMAT)}
,{Const.COL_EDIT_UID} = {dataReader.SqlValueString(Const.COL_EDIT_UID)}
,{Const.COL_EDIT_DATE} = '{YYYYMMDDHHMMSS}'
,{Const.COL_CREATE_UID} = {dataReader.SqlValueString(Const.COL_CREATE_UID)}
,{Const.COL_CREATE_DATE} = {dataReader.SqlValueString(Const.COL_CREATE_DATE)}
,{Const.COL_PRICE_FORMAT_NUM} = {dataReader.SqlValueString(Const.COL_PRICE_FORMAT_NUM)}
WHERE {Const.COL_PLS_NUM} = {dataReader.SqlValueString(Const.COL_PLS_NUM)}";
Post Reply