Private Sub Command1_Click() Dim s As String Dim b() As String Dim nS As String s = "china great wall" b = Split(s, " ") Dim i As Integer For i = 0 To UBound(b) If i = 0 Then b(i) = LCase(b(i)) Else b(i) = UCase(Left(b(i), 1)) & Right(b(i), Len(b(i)) - 1) End If nS = nS & b(i) Next i Debug.Print nS End Substring转int用cint函数 dim s as string dim i as integer s="12" i=cint(s)
感谢上面的请添加注释:UBound,Left,Right,Len,及其参数的作用。
china_great_wall 要转换成 chinaGreatWall方法1:拆分拼合法 Dim strIdentifier As String, a() As String, i As IntegerstrIdentifier = "china_great_wall"a() = Split(strIdentifier, "_")strIdentifier = LCase(a(0)) For i = 1 To Ubound(a) strIdentifier = strIdentifier & UCase(a(i)) Next i方法二:直接替换法 Dim strIdentifier As String, tmp As StringstrIdentifier = "china_great_wall" tmp = LCase(Left(strIdentifier, Instr(strIdentifier, "_") - 1)) strIdentifier = UCase(Replace(strIdentifier, "_", "")) strIdentifier = tmp & Right(strIdentifier, Len(tmp) + 1)
Dim s As String
Dim b() As String
Dim nS As String
s = "china great wall"
b = Split(s, " ")
Dim i As Integer
For i = 0 To UBound(b)
If i = 0 Then
b(i) = LCase(b(i))
Else
b(i) = UCase(Left(b(i), 1)) & Right(b(i), Len(b(i)) - 1)
End If
nS = nS & b(i)
Next i
Debug.Print nS
End Substring转int用cint函数
dim s as string
dim i as integer
s="12"
i=cint(s)
Dim strIdentifier As String, a() As String, i As IntegerstrIdentifier = "china_great_wall"a() = Split(strIdentifier, "_")strIdentifier = LCase(a(0))
For i = 1 To Ubound(a)
strIdentifier = strIdentifier & UCase(a(i))
Next i方法二:直接替换法
Dim strIdentifier As String, tmp As StringstrIdentifier = "china_great_wall"
tmp = LCase(Left(strIdentifier, Instr(strIdentifier, "_") - 1))
strIdentifier = UCase(Replace(strIdentifier, "_", ""))
strIdentifier = tmp & Right(strIdentifier, Len(tmp) + 1)