- $s = @'
- Key 1
- -
- Hello 1
- World 1
- ---
- Key 2
- -
- Hello 2
-
- World 2
- ---
- Key 3
- -
- Hello 3
- World 3
- '@
- $arr = $s -split '\r?\n';
- $out = @();
- $str = '';
- switch -regex ($arr) {
- '^---$' {
- $out += $str;
- $str = '';
- }
- default {
- $str += $_ + "`r`n";
- }
- }
- $out += $str;
- $out[0];
复制代码
|