I have a string producing results in PowerShell being separated by a comma, which is fine, but I don't want the last comma.
I understand a Trim function is required, but I can't seem to get it to work. Maybe i've been trying it in the wrong place?
I need it to return three "Site Codes, each separated with a comma, and no comma at the end. I need to know where to add the trim bit really.
$UKPRN = "10007405"
$str_sites = "A4EYORK,AVLEEDS,BANBURY";
$sites = "";
foreach ($site in $str_sites.Split(","))
{
$sites = $sites+"'"+$site+"',"
}
Write-Output $sites;
You could just use TrimEnd()
$str = "string with , at the end,"
$str.TrimEnd(",")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With