正文

PowerShell实现在字符串中查找大写字母(powershell input)干货分享

文章摘要

这篇文章介绍了如何在字符串中查找第一个大写字母的位置,并将其前后部分用特殊符号分割。代码通过遍历字符串的每个字符,当遇到第一个大写字母时记录其位置,并将字符串在该位置分割。最终输出结果为:`First uppercase character at position 0`,并显示分割后的字符串 `a` 和 `pple`。

 $text=’here is some text with Uppercase letters’ $c=0 $position=foreach ($character in $text.ToCharArray()) { $c++ if ([Char]::IsUpper($character)) { $c break } } if ($position -eq $null) { ‘No uppercase characters detected.’ } else { “First uppercase character at position $position” $text.Substring(0, $position) + “<<<” + $text.Substring($position) }