Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how to split a string without losing the character you split on.
I’m splitting this file name some file.txt into its name and extension by going “some file.txt” –split “.”. It’s giving me some file and txt, but I want to keep the dot and get .txt instead. How can I do this?
You can split on a regex lookahead and split on the space between characters where the character on the right is a dot
'some file.txt' -split '(?=\.)'