每个语句的UCase [英] UCase for each statement
问题描述
我正在尝试使用 UCase
将可能包含数字的字符串转换为UpperCase.当我用这样的线
I am trying to convert a string that may contain numbers to UpperCase using UCase
. When I used a line like that
For Each vLetter In UCase(lName)
当lName变量等于"Yasser51"时,我遇到了错误.举个例子.我该如何克服呢?
I encountered an error when the lName variable equals to "Yasser51" as an example. How can I overcome this ?
推荐答案
您不能像这样使用 For Each
. For Each
只能迭代集合或数组. String
都不是.
You can't use For Each
like this. For Each
can only iterate over a collection or an array. A String
is neither.
一个按字符循环的选项是 Mid $
和一个常规的 For
循环.(尽管您仍然不清楚您实际上在尝试做什么,甚至是否需要循环):
One option to loop character-by-character is Mid$
and a regular For
loop. (Though it's still unclear what you're actually trying to do and if a loop is even required):
Sub Test()
Dim lName As String
lName = "Yasser51"
Dim i As Long
For i = 1 To Len(lName)
Dim letter As String
letter = Mid$(UCase(lName), i, 1)
Debug.Print letter
Next
End Sub
这篇关于每个语句的UCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!