Every once in a while you may find yourself in a situation where you would like to convert a string (bunch of characters) to lower- or upper case characters… for example when creating Virtual Machines.
When you’re working with strings, it is possible to convert those characters with the “toLower()” method… like so:
But what if you want to convert lower characters to upper characters? Use the “toUpper()” method as shown below:
hi
just for fun:
$phrase = “THIS IS MY TEXT RIGHT NOW”
-join $($phrase.ToCharArray()|%{
if([char]::IsLower($_)) {$_}else{[char]::ToLower($_)}})
or this:
$phrase = “THIS IS MY TEXT RIGHT NOW”
$phrase -replace ‘(w)’,”$([char]::ToLower($1))”
Hi Walid2mi,
The “-Join” oneliner you’ve provided does work, but it’s a lot more code… yet still, it’s a different approach and fun to see that there’s another way to accomplish the same 🙂
However, the “-replace” twoliner doesn’t work…
“UPPERCASE TEST”.tolower()