10-18-2021 07:57 AM - last edited on 05-25-2023 07:38 AM by JackLacava
Hi all
How can I avoid the ampersand in string operations? I need to concatenate a pov for a calculation, but with all the ampersands, it looks complicated:
"A#" & accountName & ":F#" & flowName & ":UD2#" & ud2Name & ":UD4#" & ud4Name
Solved! Go to Solution.
10-18-2021 08:01 AM - edited 12-10-2021 05:19 AM
If you use the $" you can avoid all ampersands and ease the reading of calculation strings.
instead of
"A#" & accountName & ":F#" & flowName & ":UD2#" & ud2Name & ":UD4#" & ud4Name
you can simply write
$"A#{accountName}:F#{flowName}:UD2#{ud2Name}:UD4#{ud4Name}"
10-18-2021 08:01 AM - edited 12-10-2021 05:19 AM
If you use the $" you can avoid all ampersands and ease the reading of calculation strings.
instead of
"A#" & accountName & ":F#" & flowName & ":UD2#" & ud2Name & ":UD4#" & ud4Name
you can simply write
$"A#{accountName}:F#{flowName}:UD2#{ud2Name}:UD4#{ud4Name}"
11-17-2021 08:18 AM - edited 12-10-2021 05:20 AM
You can also format the variables like this:
$"Don't mess with Debit and Credit the difference {deltaDC:N2} is larger than 100"
DeltaDC is a decimal and will be used in the N2 number format.
12-10-2021 12:04 AM
Note that the variable is bracketed by the curly braces {}, they are hard to discern on the web page. If you copy and paste Christian's example you will see that the character is not a parentheses or square bracket.
12-10-2021 05:21 AM
Thank you Erik, I changed the samples to code samples mode, maybe it is now easier to copy.
12-14-2021 01:24 PM
When you create a string, and require Carriage Returns be inserted for formatting purposes (e.g. creating an email) you can include .net newlines.
Dim messageBody As String = $"Type - {SRType} {vbCrLf}Description - {SRDescription}"
vbCrLf or environment.newline both will work, and will create a carriage return into the message body.