1
我需要大寫每個單詞的第一個字母使用拆分加入使用PowerShell 3.0PowerShell 3字符串操作使用拆分和加入
我一直在瘋狂試圖找出這一點。
任何幫助,將不勝感激。
Function Proper([switch]$AllCaps, [switch]$title, [string]$textentered=" ")
{
if ($AllCaps)
{$textentered.Toupper()}
Elseif ($title)
{$textentered -split " "
$properwords = $textentered | foreach { $_ }
$properwords -join " "
$properwords.substring(0,1).toupper()+$properwords.substring(1).tolower()
}
}
proper -title "test test"
感謝您的意見。這是我想出的。它只是大寫第一個單詞的第一個字母。函數正確([開關] $ ALLCAPS,[開關] $標題,[字符串] $ textentered =」「){ \t如果($ ALLCAPS) \t \t {$ textentered.Toupper()} \t ELSEIF($標題) \t \t {$ textentered -split「」 \t \t $ properwords = $ textentered |的foreach {$ _} \t \t $ properwords -join 「」 $ properwords.substring(0,1).toupper()+ $ properwords.substring(1).tolower() \t \t } } proper -title「test test」 – user2608870