VBA 子程序:判断字符串第一个大写字母
以下是使用 VBA 编写的一个子程序,用于判断一个字符串的第一个大写字母是什么:\n\nvba\nSub FindFirstUpperCaseLetter()\n Dim str As String\n Dim firstUpperCase As String\n \n ' 输入字符串\n str = InputBox("请输入一个字符串:")\n \n ' 遍历字符串的每个字符,找到第一个大写字母并退出循环\n For i = 1 To Len(str)\n If Mid(str, i, 1) Like "[A-Z]" Then\n firstUpperCase = Mid(str, i, 1)\n Exit For\n End If\n Next i\n \n ' 输出结果\n If firstUpperCase <> "" Then\n MsgBox "第一个大写字母是:" & firstUpperCase\n Else\n MsgBox "字符串中没有大写字母。"\n End If\nEnd Sub\n\n\n使用此子程序时,会弹出一个对话框,要求输入一个字符串。程序会遍历该字符串的每个字符,找到第一个大写字母并输出。如果字符串中没有大写字母,则输出相应的提示信息。
原文地址: https://www.cveoy.top/t/topic/pLMP 著作权归作者所有。请勿转载和采集!