Reputation: 187
I try to do substring against 1 long string and then want to put each sub string into a new line. For example, if I have a long string "1pxxxx2pxxx1pyyyyy", the result would be 3 lines as below.
1pxxxx
2pxxx
1pyyyyy
In my case, 1p and 2p are pre-defined keyword. I really appreciate any helps. Thank you.
Upvotes: 1
Views: 209
Reputation: 437197
Use -split
, the string-splitting operator, with a positive lookahead assertion (more details here):
PS> '1pxxxx2pxxx1pyyyyy' -split '(?=1p|2p)' -ne ''
1pxxxx
2pxxx
1pyyyyy
Upvotes: 3