powershell - Add-Content With Condition On One Line -


i'm trying of on 1 line, try doesn't work. tried `b doesn't backspace line above. tried putting condition inline first add-content, didn't work either.

add-content $txtpath "p: $strphone x $strxten  |  " if ($strmobile -ne $null) { add-content $txtpath "`m: strmobile  |  " } add-content $txtpath "$strfax" 

you can't use multiple add-content calls because each 1 append newline. logged suggestion long time ago nonewline parameter on add-content. can vote here.

you can use stringbuilder , output contents via add-content or set-content:

$sb = new system.text.stringbuilder [void]$sb.append("p: $strphone x $strxten  |  ") if ($strmobile -ne $null) { [void]$sb.append("`m: strmobile  |  ") } [void]$sb.append($strfax) add-content $txtpath $sb.tostring() 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -