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