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.

1pxxxx2pxxx1pyyyyy

In my case, 1p and 2p are pre-defined keyword. I really appreciate any helps. Thank you.

askedMay 22, 2020 at 0:38
Iverson Wang's user avatar
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.CommentedMay 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.CommentedMay 22, 2020 at 3:23

1 Answer1

3

Use-split, thestring-splitting operator, with a positivelookahead assertion (more detailshere):

PS> '1pxxxx2pxxx1pyyyyy' -split '(?=1p|2p)' -ne ''1pxxxx2pxxx1pyyyyy
answeredMay 22, 2020 at 1:40
mklement0's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.