【发布时间】:2015-06-30 22:54:32
【问题描述】:
我有具有
 的字符串值。我想用\n 替换它。当我在每一行到达另一行后将其转换为 html 格式时。但这不起作用。
$StdOut = 'total 40 drwxr-xr-x 3 root root 4096 Jun 16 14:55 . drwxr-xr-x 5 root root 4096 Jun 16 14:54 .. -rw------- 1 root root    0 Jun 16 14:55 cimserver_start.lock srwxrwxrwx 1 root root    0
6 月 16 日 14:55 cim.socket drwxr-xr-x 2 root root 4096 Jun 16 17:58 localauth -rw------- 1 根根 6 Jun 16 14:55 scx-cimd.pid '
$CResult = $StdOut -replace " ", "\n"
使用Convert-html后,我有这样的文字:
'total 40\ndrwxr-xr-x 3 root root 4096 Jun 16 14:55 .\ndrwxr-xr-x 5 root root 4096 Jun 16 14:54 ..\n-rw------- 1 root root    0 Jun 16 14:55 cimserver_start.lock\nsrwxrwxrwx 1 root root    0 Jun 16 14:55
cim.socket\ndrwxr-xr-x 2 root root 4096 Jun 16 17:58 localauth\n-rw------- 1 root root    6 Jun 16 14:55 scx-cimd.pid\n
'
我该怎么做?
【问题讨论】:
-
\不是 PowerShell 中的字符转义序列,您应该使用反引号:"`n"