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

随心笔谈9个月前发布 admin
210 00
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

文章摘要

这篇文章介绍了如何在字符串中查找第一个大写字母的位置,并将其前后部分用特殊符号分割。代码通过遍历字符串的每个字符,当遇到第一个大写字母时记录其位置,并将字符串在该位置分割。最终输出结果为:`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)
}

© 版权声明

相关文章