I'm manipulating a test where I use multiple .replace
commands to format the text.
For example
$str="hello%worldZZZniceZZZtoZZZmeet"
$str.Replace("%","`n").replace("ZZZ","`n")
Output in the console is good but I need to iterate each line.
problem is $str.count = 1
meaning powershell looks at this string still as one line even when it shows up good in the console.
any idea?
If I output the string to file and then read the file it does read with new lines but there's a better way I'm sure instead of outputting to file and then reading it back again
Sounds like you're looking to split the string and get an array as result:
$str = "hello%worldZZZniceZZZtoZZZmeet"
$str -split "%|ZZZ"
($str -split "%|ZZZ").count # => 5
Since the operator is regex compatible you can use "%|ZZZ"
(split on %
or ZZZ
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With