fastest way to change case of string



Looking for the very fastest way to change a string from
upper to lower case and vice versa.
Text enclosed in single quotes needs to stay as it is.
This is the best effort I have sofar:

Function ChangeCase(strString As String, bUpper As Boolean) As String

Dim i As Long
Dim bInQuotes As Boolean
Dim btArray() As Byte

'could do in one go if no single quotes, but it doesn't make it faster
'---------------------------------------------------------------------

btArray = strString

If bUpper Then
For i = 0 To UBound(btArray) Step 2
If btArray(i) = 39 Then
bInQuotes = (bInQuotes = False)
End If
If btArray(i) > 96 And btArray(i) < 123 Then
If bInQuotes = False Then
ChangeCase = ChangeCase & UCase(Mid$(strString, i \ 2 + 1, 1))
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Next
Else
For i = 0 To UBound(btArray) Step 2
If btArray(i) = 39 Then
bInQuotes = (bInQuotes = False)
End If
If btArray(i) > 64 And btArray(i) < 91 Then
If bInQuotes = False Then
ChangeCase = ChangeCase & LCase(Mid$(strString, i \ 2 + 1, 1))
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Next
End If

End Function


Any suggestions to make it faster?

RBS

.



Relevant Pages

  • Re: fastest way to change case of string
    ... string rather than concatenating a new string is indeed much faster. ... Dim strTestLower As String ... Dim strTitle As String ... Dim bInQuotes As Boolean ...
    (microsoft.public.vb.general.discussion)
  • Re: fastest way to change case of string
    ... Number of single quotes should never be odd, so that shouldn't be a problem. ... Although it is only a small string I like it to be fast as the UCase/LCase conversion ... Dim bInQuotes As Boolean ...
    (microsoft.public.vb.general.discussion)
  • Re: fastest way to change case of string
    ... Text enclosed in single quotes needs to stay as it is. ... Function ChangeCase(strString As String, ... Dim bInQuotes As Boolean ...
    (microsoft.public.vb.general.discussion)
  • Re: fastest way to change case of string
    ... Function ChangeCase(strString As String, ... Dim bInQuotes As Boolean ... Dim btArray() As Byte ...
    (microsoft.public.vb.general.discussion)
  • Re: Yet another syntax issue.
    ... Why are you enclosing in single quotes ' if you pass this string value as a ... Dim cnn As ADODB.Connection ... Dim strJcn As String ... Set prm = cmd.CreateParameter("@Jcn", adBSTR, adParamInput,, ...
    (microsoft.public.access.adp.sqlserver)

Loading