If you want to find capital characters in a string, you might use regular expressions. Or use your capital letter list to match one by one, of course, it is more flexible to use the IsUpper() function in .NET.
Editor's note: .NET is the soil of PowerShell. Digging out the functions in these framework frameworks as much as possible is our eternal pursuit.
The following example will scan every character in the string and return to the position of the first capital letter encountered:
$text = 'here is some text with Uppercase letters' $c = 0 $position = foreach ($character in $()) { $c++ if ([Char]::IsUpper($character)) { $c break } } if ($position -eq $null) { 'No uppercase characters detected.' } else { "First uppercase character at position $position" $(0, $position) + "<<<" + $($position) }
The output result is as follows:
PS C:\>First uppercase character at position 24 here is some text with U<<