Forum Discussion
RandyRiauka
Sep 03, 2022Copper Contributor
Message: There is an unterminated string literal at position 46 in ... (Special Charater the cause)
Hi, I'm hoping someone can guide me on an issue I'm having with the error message "Message: There is an unterminated string literal at position 46 in ..." I know the cause but am unsure of the sol...
- Sep 03, 2022
Hi, Randy.
Using web-specific special characters in resources never ends well, as you're seeing. Fortunately, there is a reasonably straight-forward solution as there's many ways to encode such strings.
Here's one that uses the [uri] class to escape the displayName properly.
Using your example:
# This: Get-Team -DisplayName "Peer Tutoring - Metal Fabrication & Welding"; # Becomes this: Get-Team -DisplayName ([uri]::EscapeDataString("Peer Tutoring - Metal Fabrication & Welding"))
Cheers,
Lain
LainRobertson
Sep 03, 2022Silver Contributor
Hi, Randy.
Using web-specific special characters in resources never ends well, as you're seeing. Fortunately, there is a reasonably straight-forward solution as there's many ways to encode such strings.
Here's one that uses the [uri] class to escape the displayName properly.
Using your example:
# This:
Get-Team -DisplayName "Peer Tutoring - Metal Fabrication & Welding";
# Becomes this:
Get-Team -DisplayName ([uri]::EscapeDataString("Peer Tutoring - Metal Fabrication & Welding"))
Cheers,
Lain
- RandyRiaukaSep 03, 2022Copper Contributor