Reputation: 1493
I have this response coming back from an API, which appears to have newline characters in it. But, I cannot find what characters are actually there, and thus cannot split this string.
$response = curl.exe POST --silent --user $creds --data-raw $request $url
$response.contains("`f")
$response.contains("`r")
$response.contains("`n")
$response
Output:
False False False "92837F755","BES","780532219" "46431P106","BES","!NA" "Y2069P309","BES","!NA"
Upvotes: 1
Views: 1668
Reputation: 200533
$response
contains an array of strings. Echoing the array displays one string at a time, even though the individual strings don't contain any of the characters you're testing for.
If you want the response as a single string without newlines you can simply put the variable in double quotes:
"$response"
By default this joins the array elements with a space between them. If you don't want that you can set $OFS = ''
first, or simply join the array with an empty string:
$response -join ''
or
-join $response
If you want the response with newlines you can pipe the curl
output through Out-String
:
$response = curl.exe ... | Out-String
Upvotes: 3