Split a string in PowerShell
Fairly simple to do using a regex with negative and positive lookahead (?=pattern)
and the case-sensitive -csplit
operator e.g.:
PS> "HelloWorldIAmNewToScripting" -csplit "(?<=.)(?=[A-Z])"HelloWorldIAmNewToScripting
Or if you want it space separated:
PS> "$("HelloWorldIAmNewToScripting" -csplit "(?<=.)(?=[A-Z])")"Hello World I Am New To Scripting
Try this:
("HelloWorldIAmNewToScripting" -creplace '[A-Z]', ' $&').Trim().Split($null)HelloWorldIAmNewToScripting
or
("HelloWorldIAmNewToScripting" -creplace '[A-Z]', ' $&').Trim()Hello World I Am New To Scripting