1

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.

2
  • What would be the "rule" where to split your string into pieces? What have you tried so far? You know you are expected to make an own attempt to solve your problem. Commented May 22, 2020 at 1:18
  • To achieve my goal, I tried to combine substring and carriage return but had no luck. I'll post my query next time. Commented May 22, 2020 at 3:23

1 Answer 1

3

Use -split, the string-splitting operator, with a positive lookahead assertion (more details here):

PS> '1pxxxx2pxxx1pyyyyy' -split '(?=1p|2p)' -ne ''
1pxxxx
2pxxx
1pyyyyy
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.