Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Split Strings with Capital Letters and Numbers

$
0
0

Hi

I have got a Powershell line below that split a string with capital letters into spaces which is great.

$test = "OnceUponATime"
$test = ($test.substring(0,1).toupper() + $test.substring(1) -creplace '[A-Z]', ' $&').Trim();

The output is Once Upon A Time which is great

But the problem comes when $test = "OnceUponATime1" gives you Once Upon A Time1 instead of Once Upon A Time 1

$test = "Money@Risk" should return "Money @ Risk"

Any idea what is wrong with my powershell statement?


Thanks



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>