Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Take the following snippet
'a',$null,'b'
This is the result
a b
Is there a way to change this default? So that null is actually treated in output as something.
There's no way to change that behaviour, but as a workaround you can do this:
[string[]]('a',$null,'b')
to get the desired result.
Add a comment
This will turn the $null into a blank string:
'a',$null,'b' | % { "$_" }
Or you could transform the $null into some arbitrary string such as '[null]':
$null
'[null]'
'a',$null,'b' | % { if ($_ -ne $null) {$_} else {'[null]'} }
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.